I feel like I am missing something obvious trying to access key 784 in an array. Consider the following code:
$cart_str = isset($_COOKIE['cart'])?$_COOKIE['cart']:"{}";
echo $cart_str . "\n\n";
$cart_arr = (array) json_decode($cart_str);
var_dump($cart_arr);
var_dump($cart_arr['784']);
var_dump($cart_arr[784]);
This is the output from the above:
{"780":{"qty":"1","pid":"780"},"784":{"qty":"1","pid":"784"},"794":{"qty":"1","pid":"794"}}<br>array(3) {
["780"]=>
object(stdClass)#3 (2) {
["qty"]=>
string(1) "1"
["pid"]=>
string(3) "780"
}
["784"]=>
object(stdClass)#4 (2) {
["qty"]=>
string(1) "1"
["pid"]=>
string(3) "784"
}
["794"]=>
object(stdClass)#5 (2) {
["qty"]=>
string(1) "1"
["pid"]=>
string(3) "794"
}
}
<br />
<b>Notice</b>: Undefined offset: 784 in <b>C:\Users\John\Dropbox\htdocs\uzepi_com_test\cart.php</b> on line <b>34</b><br />
NULL
<br />
<b>Notice</b>: Undefined offset: 784 in <b>C:\Users\John\Dropbox\htdocs\uzepi_com_test\cart.php</b> on line <b>35</b><br />
NULL
I was expecting to get an object printed out that looked like this corresponding item in the array with key 784.