note 24477 added to function.array-filter

From: Date: Sat, 17 Aug 2002 17:04:04 +0000
Subject: note 24477 added to function.array-filter
Groups: php.notes 
Request: Send a blank email to php-notes+get-35171@lists.php.net to get a copy of this message
I was looking for a function to delete values from an array and thought I had found it in array_filter(), however, I *didn't* want the keys to be preserved *and* I needed blank values cleaned out of the array as well. I came up with the following (with help from many of the above examples): function array_delete($array, $filterfor){ $thisarray = array (); foreach($array as $value) if(stristr($value, $filterfor)===false && strlen($value)>0) $thisarray[] = $value; return $thisarray; } $array1 = array ('OtHeR','this', 'that', 'Other','', 9, 101, 'fifty', 'other','',''); echo "<pre>array :\n"; print_r($array1); $array2=array_delete($array1, "Other"); echo "filtered:\n"; print_r($array2); -- http://www.php.net/manual/en/function.array-filter.php http://master.php.net/manage/user-notes.php?action=edit+24477 http://master.php.net/manage/user-notes.php?action=delete+24477 http://master.php.net/manage/user-notes.php?action=reject+24477

« previous php.notes (#35171) next »