Append a parent element to arrays in PHP for a foreach loop

Posted by Erik Berger on Stack Overflow See other posts from Stack Overflow or by Erik Berger
Published on 2012-11-27T23:02:24Z Indexed on 2012/11/27 23:03 UTC
Read the original article Hit count: 231

Filed under:
|
|
|

print_r of $data = json_decode($src, true); returns data that looks like this:

Array ( 
[0] => Array ( 
 [var1] => blah
 [var2] => foo
 ) 
[1] => Array ( 
 [var1] => lorem 
 [var2] => ipsum
 )
  // goes down to [1936]
) 

I want to build an html table that shows var1 and var2 next to each other in the same row. I know do to this I need a foreach statement like

foreach($data['items'] as $item)

but the problem I think I am having is that my many arrays aren't the child of one thing like 'items', right?

I looked into array_push but couldn't figure it out. Can someone help my orphaned parentless arrays?

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays