How to loop through an array of objects that have been decoded from JSON in PHP, and echo the values -


i'm new php , not sure how proceed. array decoding json is: (sorry if 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" } } 

i have used foreach loop, not sure how each individual item out of associative array.

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

this returns:

012 

i have tried other solutions, no avail. maybe i'm not understanding what's happening, can't need/want. thanks!

you have nested objects, try following:

echo '<table>';  foreach ($obj $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>'; 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -