RE: [PHP] array_filter function

2008-03-28 Thread Bagus Nugroho
Thanks You,
 
rgds, bnug



From: Robin Vickery [mailto:[EMAIL PROTECTED]
Sent: Jumat 28-Mar-2008 21:45
To: Bagus Nugroho
Cc: php-general@lists.php.net
Subject: Re: [PHP] array_filter function



On 28/03/2008, Bagus Nugroho <[EMAIL PROTECTED]> wrote:
> Hello,
>
>  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'))

$newDataArray = array_filter($dataArray, create_function('$a','return
$a["type"] == "da";'));





Re: [PHP] array_filter function

2008-03-28 Thread Robin Vickery
On 28/03/2008, Bagus Nugroho <[EMAIL PROTECTED]> wrote:
> Hello,
>
>  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'))

$newDataArray = array_filter($dataArray, create_function('$a','return
$a["type"] == "da";'));

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



Re: [PHP] array_filter function

2008-03-28 Thread Richard Heyes

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:

 $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



[PHP] array_filter function

2008-03-28 Thread Bagus Nugroho
Hello,

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'))

Thanks in advance

bnug

 

 





[PHP] array_filter

2003-02-25 Thread David Otton
I suspect this can't be done in PHP. However...

Is it possible to pass additional parameters to the callback function
used by array_filter()?

I guess I'm looking for something functionally equivalent to this Python
code:

from string import count

list = ('apple', 'avacado', 'banana', 'blueberry', 'peach', 'persimmon')
strings = ['a', 'b', 'c', 'd', 'e', 'f']

for string in strings :
print filter(lambda x : count(x, string), list)


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