从 JSON 输入中检索数组键 [英] Retrieving array keys from JSON input
本文介绍了从 JSON 输入中检索数组键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个数组:
$json = json_decode('
{"entries":[
{"id": "29","name":"John", "age":"36"},
{"id": "30","name":"Jack", "age":"23"}
]}
');
我正在寻找一个 PHPfor each"循环,它可以检索 entries
下的键名,即:
and I am looking for a PHP "for each" loop that would retrieve the key names under entries
, i.e.:
id
name
age
我该怎么做?
推荐答案
尝试
foreach($json->entries as $row) {
foreach($row as $key => $val) {
echo $key . ': ' . $val;
echo '<br>';
}
}
在 $key 中你应该得到键名,在 val 中你应该得到值
In the $key you shall get the key names and in the val you shal get the values
这篇关于从 JSON 输入中检索数组键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文