I am trying to add data in from SQL loop into a specific section of an array, however it does't seem to keep the array format when I do a json encode.
I create the array:
$array['type'] = 'update';
$array['tags']['data'] = array(array('name' => "Tag", 'tags' => array()));
Then in my sql loop in the while:
$array['tags']['data']['tags'][] = array('a' => "$row[a]", 'b' => "$row[b]");
after this loop, json encode:
json_encode($array);
In the output, the "tags" has the rows added under data, and the one I setup for the array is now under tags:data:0:tags , and it has not populated this.
Also data
has gone from [ ]
to { }
, and I need it to be [{ }]
. If I take out the loop, the data section is with [ { } ]
as expected.
Hope that makes sense! if not can expand more.
Many thanks