如何通过对象的数组已经去codeD从JSON在PHP中循环,呼应值 [英] How to loop through an array of objects that have been decoded from JSON in PHP, and echo the values

查看:110
本文介绍了如何通过对象的数组已经去codeD从JSON在PHP中循环,呼应值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我新的PHP和我不知道如何着手。我回来从JSON解码的数组是:(抱歉,如果其格式化怪异)

I'm new to PHP and am not sure how to proceed. The array that I get back from decoding the JSOn is: (sorry if its formatted weird)

array(3) {
 [0]=> array(4) { 
   ["Name"]=> string(22) "Brent's Medical Center"
   ["date"]=> string(26) "/Date(1330449077600-0700)/"
   ["dealType"]=> string(13) "Capital Lease" 
   ["id"]=> string(11) "MO-N007175A" 
 } 
 [1]=> array(4) { 
   ["Name"]=> string(22) "Brent's Medical Center" 
   ["date"]=> string(26) "/Date(1330448929213-0700)/" 
   ["dealType"]=> string(2) "NA"  ..... ["id"]=> string(11) "MO-N007172Q" } [2]=> array(4) { ["Name"]=> string(15) "MOC" ["date"]=> string(28) "/Date(-62135571600000-0700)/" ["dealType"]=> string(2) "NA" ["id"]=> string(9) "MC" } }

我已经使用这个foreach循环,但我不知道如何让各个项目进行的关联数组。

I have used this foreach loop, but am not sure how to get each individual item out of an associative array.

foreach ($obj as $key => $value) {
    print_r($key);
}

这将返回:

012

我曾尝试其他解决方案,但无济于事。也许我不理解完全发生了什么,但我不能得到什么做什么,我需要/想。
谢谢!

I have tried other solutions, but to no avail. Maybe I'm not understanding completely what's happening, but I can't get anything to do what I need/want. Thanks!

推荐答案

您已经嵌套的对象,请尝试以下操作:

You have nested objects, try the following:

echo '<table>';

foreach ($obj as $key => $value) {
    echo '<tr>';
    echo '<td>' . $value->Name . '</td>';
    echo '<td>' . $value->date . '</td>';
    echo '<td>' . $value->dealType . '</td>';
    echo '<td>' . $value->id . '</td>';
    echo '</tr>';
}

echo '</table>';

这篇关于如何通过对象的数组已经去codeD从JSON在PHP中循环,呼应值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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