Re: [PHP] array_filter function
- From: richardh@xxxxxxxxxxx (Richard Heyes)
- Date: Fri, 28 Mar 2008 14:11:11 +0000
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
.
- References:
- [PHP] Use of callback on a stream
- From: Olivier Dupuis
- array_filter function
- From: "Bagus Nugroho"
- [PHP] Use of callback on a stream
- Prev by Date: array_filter function
- Next by Date: Re: [PHP] munge / obfuscate ?
- Previous by thread: array_filter function
- Next by thread: Re: [PHP] array_filter function
- Index(es):
Relevant Pages
|