Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could just reduce that array to the entries you want. Keep in mind this will preserve the original keys, So you may end up with an array that has 0, 1, and 3 as keys if 2 was unset during the process.</p> <pre><code>foreach( $array as $key =&gt; &amp;$value ){ if ( $value['type'] != 'A' ) unset( $array[ $key ] ); } </code></pre> <p>Demo: <a href="http://codepad.org/OG5rguJ8" rel="nofollow">http://codepad.org/OG5rguJ8</a></p> <p>Another method is to use <code>array_filter</code> to iteratively reduce the array one entry at a time:</p> <pre><code>function callbackFunc( $val ) { return $val['type'] == 'A'; } $result = array_filter( $array, callbackFunc ); </code></pre> <p>We call the <code>array_filter</code> method passing in the array we'd like to filter, as well as the filtering function we've created. Our function will be ran against each element within the array, treating the current element as a <code>$val</code> variable.</p> <p>If that variable's type key maps to a value that is <code>==</code> to "A", <code>TRUE</code> is returned. Otherwise, <code>FALSE</code> is returned. When the function returns <code>TRUE</code>, the evaluated value is sent to the <code>$result</code> array. If <code>FALSE</code> was returned, the value is not pushed onto the <code>$result</code> array.</p> <p>Like the previous option, this method will also preserve the key values.</p> <p>Demo: <a href="http://codepad.org/todHBZo7" rel="nofollow">http://codepad.org/todHBZo7</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload