从JSON输入检索数组键 [英] Retrieving array keys from JSON input

查看:107
本文介绍了从JSON输入检索数组键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的数组:

$json = json_decode('
{"entries":[
{"id": "29","name":"John", "age":"36"},
{"id": "30","name":"Jack", "age":"23"}
]}
');

和我正在寻找一个PHP为每一个循环,将检索在键名,即:

and I am looking for a PHP "for each" loop that would retrieve the key names under entries, i.e.:

id
name
age

我怎样才能做到这一点?

How can I do this?

推荐答案

试用

foreach($json->entries as $row)
{
    foreach($row as $key => $val)
    {
        echo $key . ': ' . $val;
        echo '<br>';
    }
}

在$关键你要拿到钥匙的名称和在Val你SHAL获取值

In the $key you shall get the key names and in the val you shal get the values

这篇关于从JSON输入检索数组键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆