Re: array_filter function

From: Date: Fri, 28 Mar 2008 14:11:11 +0000
Subject: Re: array_filter function
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-272220@lists.php.net to get a copy of this message
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

« previous php.general (#272220) next »