title: PHP: Merge arrays in loop
body: <pre><code>   public function getCheckoutForm(){
     $arr = array(
          'cmd' =&gt; '_cart',
          'business' =&gt; 'some@mail',
          'no_shipping' =&gt; '1',
          'upload' =&gt; '1',
          'return' =&gt; 'url',
          'cancel_return' =&gt; 'url1',
          'no_note' =&gt; '1',
          'currency_code' =&gt; 'url2',
          'bn' =&gt; 'PP-BuyNowBF');
  
     $cpt=1;
     foreach($this-&gt;items as $item){
          $arr1[] = array(
              'item_number_'.$cpt.'' =&gt; $item['item_id'],
              'item_name_'.$cpt.'' =&gt; $item['item_name'],
              'quantity_'.$cpt.'' =&gt; $item['item_q'],
              'amount_'.$cpt.'' =&gt; $item['item_price']
              );
          $cpt++;
     }
      return array_merge($arr,$arr1[0],$arr1[1]);
  }
  </code></pre>
  
  <p>This returns array like that:</p>
  
  <pre><code>    Array
  (
      [cmd] =&gt; _cart
      [business] =&gt; some@mail
      [no_shipping] =&gt; 1
      [upload] =&gt; 1
      [return] =&gt; url1
      [cancel_return] =&gt;url2
      [no_note] =&gt; 1
      [currency_code] =&gt; EUR
      [bn] =&gt; PP-BuyNowBF
      [item_number_1] =&gt; 28
      [item_name_1] =&gt; item_name_1
      [quantity_1] =&gt; 1
      [amount_1] =&gt; 5
      [item_number_2] =&gt; 27
      [item_name_2] =&gt; item_name_2
      [quantity_2] =&gt; 1
      [amount_2] =&gt; 30
  )
  </code></pre>
  
  <p>The problem is that in return $arr1[0] and $arr1[1] are hardcoded. And if in loop i have more than 2 arrays, lets say 0,1,2,3 ans so on, this code won't work. Any idea? Maybe my logic is compleatly wrong...</p>