Array cannot get value by key from unserialize. It show error Undefined offset, but the array has the index call "1134". How can I get the index 1134 value?
$original = unserialize('O:8:"stdClass":1:{s:4:"1134";i:1;}');
$result = (array)$original;
print_r ($result); //Array ( [1134] => 1 )
print_r($result["1134"]); //Undefined offset: 1134
print_r($result['1134']); //Undefined offset: 1134
print_r($result[1134]); //Undefined offset: 1134
You've to iterate over your unserialized data and then store it into an array:
<?php
$original = unserialize('O:8:"stdClass":1:{s:4:"1134";i:1;}');
$arr = [];
foreach($original as $key => $values) {
$arr[$key] = $values;
}
echo $arr[1134] // outputs 1
?>
Output:-https://3v4l.org/B94OS#v5638
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With