title: Arranging PHP array based on pattern
body: <p>Given the fallowing $array: </p>
  
  <pre><code>Array (
  
  [0] =&gt; Array
      (
          [location_id_keep] =&gt; 25
          [location_id_delete] =&gt; 1
      )
  
  [1] =&gt; Array
      (
          [location_id_keep] =&gt; 26
          [location_id_delete] =&gt; Array
              (
                  [0] =&gt; 3
                  [1] =&gt; 4
              )
  
      )
  
  )
  </code></pre>
  
  <p>I want to group elements like the fallowing pattern to result:</p>
  
  <pre><code>Array (
  
  [0] =&gt; Array
      (
          [location_id_keep] =&gt; 25
          [location_id_delete] =&gt; 1
      )
  
  [1] =&gt; Array
      (
          [location_id_keep] =&gt; 26
          [location_id_delete] =&gt; 3
  
      )
  
  [2] =&gt; Array
      (
          [location_id_keep] =&gt; 26
          [location_id_delete] =&gt; 4
  
      )
  
  )
  </code></pre>
  
  <p>The rule should be like this, for each array from the input array, group the [location_id_keep] with each [location_id_delete] resulting a new array for each [location_id_delete] like in the desired output example.</p>
  
  <p>What I tried so far :</p>
  
  <pre><code>foreach ($array as $id) {
  //check if location_id_delete have more than 1 value
                  if( $id["location_id_delete"][1]) {
                      foreach($id["location_id_delete"] as $del){
                           $array["location_id_delete"][] = $del;
  
                      $array["location_id_keep"]=id["location_id_keep"];
                      }
                  }
              }
  </code></pre>