我有这个数组:
$json = json_decode(' {"entries":[ {"id": "29","name":"John", "age":"36"}, {"id": "30","name":"Jack", "age":"23"} ]} ');
并且我正在寻找一个PHP“ for each”循环,该循环将检索下的键名entries,即:
entries
id name age
我怎样才能做到这一点?
试试吧
foreach($json->entries as $row) { foreach($row as $key => $val) { echo $key . ': ' . $val; echo '<br>'; } }
在$ key中,您将获得密钥名称,在val中,您将获得值