filtering an array

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Xerpher
New php-forum User
New php-forum User
Posts: 164
Joined: Tue Aug 27, 2002 8:25 pm
Location: Ontario, Canada
Contact:

filtering an array

Postby Xerpher » Sun Feb 23, 2003 5:30 pm

Is there a function that will filter out all empty nodes of an array?

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » Mon Feb 24, 2003 6:26 am

as posted from http://www.php.net/array_filter

Code: Select all

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


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 2 guests

cron