Re: [PHP] array_filter function



If I have an array like this
$dataArray = array(0=>array('type'=>'da'), 1=>array('type'=>'wb'), 2=>array('type'=>'da');

How I can filtering to get only 'da' only, like this

$newDataArray = array(0=>array('type'=>'da'),2=>array('type'=>'da'))

Off the top of my head:

<?php
foreach ($newDataArray as $k => $v) {
if (!empty($v['type']) AND $v['type'] != 'da') {
unset($newDataArray[$k]);
}
}
?>

Optionally, you could use array_values() to re-index $newDataArray if you need to.

--
Richard Heyes
Employ me:
http://www.phpguru.org/cv
.



Relevant Pages

  • RE: [PHP] array_filter function
    ... Subject: [PHP] array_filter function ... If I have an array like this ... How I can filtering to get only 'da' only, ... $newDataArray = array_filter($dataArray, create_function('$a','return ...
    (php.general)
  • Re: [PHP] Download multiple sound files?
    ... hour downloading SPAM, just to delete it, I had to go and write a PHP ... script on the server that did the filtering, ...
    (php.general)
  • HTTP filtering with PHP & Apache ?
    ... filtering with php on an apache 2 server. ... But I didn't found an example which is related to PHP. ...
    (comp.lang.php)
  • Re: Hack attempt
    ... It is a feature in PHP which you should ... This is a common web apps vulnerabilites. ... The host should be restricted to the only connections it is supposed ... In this case, a proper network filtering ...
    (Focus-Linux)
  • Re: HTTP filtering with PHP & Apache ?
    ... If you want to generate HTML output from XSL transformations using XML data ... > filtering with php on an apache 2 server. ...
    (comp.lang.php)