Adding arrays to multi-dimensional array within loop Adding arrays to multi-dimensional array within loop codeigniter codeigniter

Adding arrays to multi-dimensional array within loop


This is because array_merge is not the right operation for this situation. Since all the $playerdata arrays have the same keys, the values are overridden.


You want to use array_push to append to an array. This way you will get an array of $playerdata arrays.

array_push($allplayerdata, $playerdata);

Which is equivalent to adding an element with the square bracket syntax

$allplayerdata[] = $playerdata;


This will add the second array to the first array: A merge is something different.

$allplayerdata[] = $playerdata;