 <p>thats because you have declaired the array within the loop. everytime the loop starts again, the array is resetted with null values and hence the final loop value is shown in result.</p> <p>declair these outside the loop and it will work fine,</p> <pre><code>$first_arr = array('one', 'two', 'three'); $second_arr = array('four', 'five', 'six'); for ($counter = 1; $counter &lt;= 5; $counter++) { foreach ($first_arr as $x) { $total[] = $x; } foreach ($second_arr as $x) { $total[] = $x; } } </code></pre>