I have the following JSON code:
"events":[[457270,70,1,2,[31,"P"],{"0":["S","0","0"],"1":["F","4","2"],"2":["P","0","0"]}...
I want to fetch the result from:
"1":["F","4","2"]
what I have is an foreach statement like this:
foreach($array->events as $key=>$val){
foreach($val->1 as $team) {
}
}
I want to fetch the values 4 and 2. Can someone help me? The statement foreach($val->1...) is not allowed. (The number 1 throws error).
$decoded = json_decode($events,TRUE);
var_dump($decoded);
You get the json response as an associative array now. You can see the output in var_dump, and you can select the necessary data as per the need.
From your var_dump
, it appears that it's an array, not an object, so try
foreach($val["1"] as $team) {
// ...
}