Trying to access array offset on value of type bool in PHP 7.4
Easy with PHP ??
null coalescing operator
return $Row['Data'] ?? 'default value';
Or you can use as such
$Row['Data'] ??= 'default value';
return $Row['Data'];
Error : Trying to access array offset on value of type int
$key
is probably not a string, you can use gettype()
to check.
You can access to number digits with substr()
:
for ($i=0; $i<strlen($string); $i++){
$ord = ord(substr($string, $i, 1));
If you prefer use array-access you must cast $string
to (string)
:
function strToHex($string){
$string = (string)$string;
A final propal could be :
function strToHex($string)
{
$result = '';
$n = strlen($string);
for ($i = 0; $i < $n; $i++) {
$c = substr($string, $i, 1);
$c = ord($c);
$result .= sprintf('%02X', $c);
}
return $result;
}
echo strToHex(1234); // 31323334
echo strToHex('Yop!'); // 596F7021
Related Topics
How to Get Beanstalkd Queue to Work for PHP
The Post Method Is Not Supported for This Route. Supported Methods: Get, Head. Laravel
Executing MySQLi_Query Inside a Function
Upload a File Using File_Get_Contents
How to Get the Total Number of Rows of a Group by Query
Convert All Types of Smart Quotes with PHP
Calculate Difference Between Two Dates Using Carbon and Blade
Symfony2 - Creating Own Vendor Bundle - Project and Git Strategy
Not Equal to != and !== in PHP
How to Check If There Is a There Is a Wget Instance Running
Trying to Access Array Offset on Value of Type Bool in PHP 7.4
Post Form and Update Multiple Rows with MySQL
How to Build a JSON Array from MySQL Database
How to Embed Images in HTML Email
Convert Utc Offset to Timezone or Date
Mcrypt_Encrypt to Openssl_Encrypt, and Openssl_Zero_Padding Problems