title: PHP create key => value pairs within a foreach
body: <p>I want to create a key-value pairs in an array within a foreach.  Here is what I have so far:</p>
  
  <pre><code>function createOfferUrlArray($Offer) {
      $offerArray = array();
  
      foreach ($Offer as $key =&gt; $value) { 
          $keyval = array($key =&gt; $value[4] );
  
          array_push($offerArray,$keyval);
      }
  
      return $offerArray;
  }   
  </code></pre>
  
  <p>If I declare the array within the foreach, it will overwrites it on each iteration, but defining it outside the foreach doesn't work either and causes triplets:</p>
  
  <pre><code>array[0] =&gt; key =&gt; value
  array[1] =&gt; key =&gt; value 
  </code></pre>
  
  <p>How do I make it so I only get key-value pairs like this?</p>
  
  <pre><code>key =&gt; value
  key =&gt; value
  </code></pre>