如何在PHP中循环遍历JSON对象值? [英] How to loop through JSON object values in PHP?
本文介绍了如何在PHP中循环遍历JSON对象值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个JSON对象,我想遍历这些值:
I have a JSON Object and I want to loop through the values:
$json = '{"1":a,"2":b,"3":c,"4":d,"5":e}';
$obj = json_decode($json, TRUE);
for($i=0; $i<count($obj['a']); $i++) {
echo $i;
}
我希望$i
显示对象中的值abcde
.
I want the $i
to display the abcde
that are the values in the object.
推荐答案
尝试使用.
$json = '{"1":"a","2":"b","3":"c","4":"d","5":"e"}';
$obj = json_decode($json, TRUE);
foreach($obj as $key => $value)
{
echo 'Your key is: '.$key.' and the value of the key is:'.$value;
}
p.s未测试;-)
这篇关于如何在PHP中循环遍历JSON对象值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文