php json decode issue
439
$data = json_decode($json,true);
echo $json;
When I use json_decode I get back a JSON tree like this:
[
"name",
[
"jason",
"carl",
"simpson",
"crew",
"marx"
]
]
So, how can I useforeach
to get all the name values?
Answer
Solution:
Like this:
Output:
EDIT
Basically The json data is an array, where
$data[0]
is the value name, and$data[1]
is a subarray that has the names you wantAnswer
Solution:
Answer
Solution:
If it was always the same structure, you could just loop over
$data[1]
.But it looks like it's some sort of key prefix structure. Then for reliability I'd use:
Answer
Solution:
the $data variable now contains a 2-dimensional array. If you want to get an array of all the names, you say