title: How to remove value from Multidimensional Array based on Key and Value - PHP
body: <p>How can I remove value <strong>"288"</strong> from <strong>"pecan"</strong> and return the updated array.</p>
  
  <p>Array like so:</p>
  
  <pre><code>a: 10: {
  s: 13: "Fraser Island";
  a: 7: {
      i: 0;
      i: 303;
      i: 1;
      i: 34;
      i: 2;
      i: 27;
      i: 3;
      i: 291;
      i: 4;
      i: 293;
      i: 5;
      i: 37;
      i: 6;
      i: 288;
  }
  s: 5: "pecan";
  a: 5: {
      i: 0;
      i: 34;
      i: 1;
      i: 27;
      i: 2;
      i: 291;
      i: 3;
      i: 59;
      i: 4;
      i: 288;
  }
  s: 11: "New Triper";
  a: 3: {
      i: 0;
      i: 291;
      i: 1;
      i: 293;
      i: 2;
      i: 288;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Which translates to this in PHP:</p>
  
  <pre><code>Array ( 
  [0] =&gt; Array ( 
      [Fraser Island] =&gt; Array ( 
          [0] =&gt; 303 
          [1] =&gt; 34 
          [2] =&gt; 27 
          [3] =&gt; 291 
          [4] =&gt; 293 
          [5] =&gt; 37 
          [6] =&gt; 288 
      )
      [pecan] =&gt; Array ( 
          [0] =&gt; 34 
          [1] =&gt; 27 
          [2] =&gt; 291 
          [3] =&gt; 59 
          [4] =&gt; 288 
      ) 
      [New Triper!] =&gt; Array ( 
          [0] =&gt; 291 
          [1] =&gt; 293 
          [2] =&gt; 288 
      )
  )
  </code></pre>
  
  <p>)</p>
  
  <p>Delete/remove a value from a multidimensional array by finding the array column name and the value. I use this code:</p>
  
  <pre><code>// DELETE VALUE FROM ARRAY
  function remove_element_by_value($arr, $val) {
      $return = array(); 
      foreach($arr as $k =&gt; $v) {
          if(is_array($v)) {
              $return[$k] = remove_element_by_value($v, $val); //recursion
              continue;
          }
          if($v == $val) continue;
              $return[$k] = $v;
          }
     return $return;
  }
  </code></pre>
  
  <p>However it removes all matching values from all array columns.</p>