Forum Moderators: coopster
foreach ($var1 as $var2) {
$statsarray=array(1 => $stats);
print_r(array_values($statsarray));
}
It goes through the foreach right and the print_r displays all the different stats, but there are in separate arrays, and I need them to be added together so they are all in the same array? Thank you.
why use this foreach
foreach ($var1 as $var2) {
when var2 isn't even used in the loop?
how are they inseperate arrays? It looks like you would be overwriting the same var on each iteration.
do you just want to add
$statsarray[]=array(1 => $stats);
but then every element would have the same key of 1 and then you should use a counter to increment, or something.
If the only important part is that you get stats into an array, then you could also just do this
$statsarray[] = $stats;
and just initialize statsarray before your foreach like so
$statsarray = array();
though, again, that should be the same value everytime since the rest of the loop does nothing to the value of stats.