title: Searching for a value inside an array and getting the array
body: <p>I am trying to use an array to search for a value that is inside of an array and then take the full array that the value is in and add it to an array.  Below is the array to get the value from:</p>
  
  <pre><code>Array (
      [0] =&gt; Array ( [ID] =&gt; 138 [dimmer] =&gt; 5 [order] =&gt; 1 [double] =&gt; 0 [location1] =&gt; DSR [location2] =&gt; Stage Pockets ) 
      [1] =&gt; Array ( [ID] =&gt; 139 [dimmer] =&gt; 6 [order] =&gt; 1 [double] =&gt; 0 [location1] =&gt; DSR [location2] =&gt; Stage Pockets )
      [2] =&gt; Array ( [ID] =&gt; 140 [dimmer] =&gt; 7 [order] =&gt; 2 [double] =&gt; 0 [location1] =&gt; DSR [location2] =&gt; Stage Pockets )
      [3] =&gt; Array ( [ID] =&gt; 141 [dimmer] =&gt; 8 [order] =&gt; 2 [double] =&gt; 0 [location1] =&gt; DSR [location2] =&gt; Stage Pockets )
  )
  </code></pre>
  
  <p>I am trying to get the value of <code>dimmer</code> with the search function below:</p>
  
  <pre><code>function search($array, $key, $value)
  {
    $results = array();
  
    if (is_array($array))
    {
        if (isset($array[$key]) &amp;&amp; $array[$key] == $value)
            $results[] = $array;
  
        foreach ($array as $subarray)
            $results = array_merge($results, search($subarray, $key, $value));
    }
  
    return $results;
  }
  </code></pre>
  
  <p>Below it uses the <code>$chan</code> value which is an integer to use the function above to search an array.  The <code>foreach</code> is then supposed to go through the array that is <code>$patch</code> and select the arrays out of the array above (only returns an empty array), although it doesn't do that unless you change <code>$patch_single['dimmer']</code> with a string such as <code>"7"</code>.</p>
  
  <pre><code>  $patch = search($patch, 'Channel', $chan);
    foreach ($patch as $patch_single) {
      print_r($patch_single);
      $dim_single = intval($patch_single['dimmer']);
      echo $dim_single;
      $dimmers = search($dimmers, 'dimmer', $dim_single);
    }
  </code></pre>
  
  <p>The array that is being used to get <code>$patch_single['dimmer']</code> is, when inside the <code>foreach</code>:</p>
  
  <pre><code>Array ( [ID] =&gt; 241 [Channel] =&gt; 100 [dimmer] =&gt; 7 )
  Array ( [ID] =&gt; 242 [Channel] =&gt; 100 [dimmer] =&gt; 25 )
  </code></pre>
  
  <p>Thank you for your advice.</p>