The code provided below is an abstract of my real code. I want to add items from a number of arrays to a final array using multiple loops. But I also want to add the the same values multiple times, hence wrapping everything in another loop. It sounds messy but I think the code explains it well. Why am I only getting the results from one loop? In other words, why is $total only containing the six elements one-six and not 30 elements (one-six five times), as one would expect with the for loop?
for ($counter = 1; $counter < 5; $counter++) {
$first_arr = array('one', 'two', 'three');
$second_arr = array('four', 'five', 'six');
$total = array();
foreach ($first_arr as $x) {
$total[] = $x;
}
foreach ($second_arr as $x) {
$total[] = $x;
}
}
var_dump($total);
Place following line outside for loop