Re: array_filter function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux