I am trying to change a PHP script so that it can recieve a JSON object and work with that given JSON object. Everything works fine until I try to cycle trhough the converted-from-JSON-array-of-objects (aka 'stuff') with the for loop.
What am I doing wrong here:
$json = '{
"foo": "hi",
"bar": "bye"
"stuff": [{"widget":"dd"},{"thing":"cc"},{"wcha":"dd"}]
}';
$arr = json_decode($json, true);
$foo = $arr['foo']; //works fine
$bar = $arr['bar']; //works fine
//old way that worked:
//$stuff = array("widget" => "dd", "thing" => "cc", "wcha" => "dd");
//new way that does not work:
$stuff = $arr['stuff'];
...
//This is where the problem is:
foreach ($stuff as $key => $value){...
The problem in the for loop is that $key is an integer (not the actual value) and $value is the word 'Array' (not the actual value).