title: PHP array_merge vs foreach loop
body: <p>I was working on a Laravel project. Where I had to marge 3 arrays. Array sizes may be big or empty. Firstly my concept was using</p>
  <pre><code>array_merge($first_array, $second_array, $third_array)
  </code></pre>
  <p>FYI array has only numbers. One array element may belong to another array. I don't need to remove duplicates or sort arrays. But it is mandatory that the first array data must be first on merged_array.</p>
  <p>Somehow it wasn't performing well. Then I wrote this code there.</p>
  <pre><code>foreach ($array2 as $i) { $array1[] = $i; }
  </code></pre>
  <p>Now my curiosity is which code is faster or efficient. With large data or less data.</p>
  <p>My experience with</p>
  <ul>
  <li>10k data (sum of 3 arrays)</li>
  <li>1k data (sum of 3 arrays)</li>
  </ul>
  <p>Results</p>
  <ul>
  <li><p>1 no results</p>
  <ul>
  <li>array_merge takes time of n</li>
  <li>foreach takes time of sqrt(n)</li>
  </ul>
  </li>
  <li><p>2 no results</p>
  <ul>
  <li>array_merge takes time of n</li>
  <li>foreach takes time of n^2</li>
  </ul>
  </li>
  </ul>