Append a parent element to arrays in PHP for a foreach loop
- by Erik Berger
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?