Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

filtering an array

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

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?
Xerpher
New php-forum User
New php-forum User
 
Posts: 164
Joined: Tue Aug 27, 2002 8:25 pm
Location: Ontario, Canada

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);
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.