note 34373 added to ref.array
| From: | qartis at rack1 dot php dot net | Date: | Fri, 25 Jul 2003 06:54:20 +0000 |
| Subject: | note 34373 added to ref.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-52607@lists.php.net to get a copy of this message | ||
To remove blank entries from an array:
function array_clean($array){
for($i=0;$i<count($array);$i++) {
if (trim($array[$i])==""){
array_splice ($array, $i, 1);
$i--;
}
}
return $array;
}
Usage:
$array = array("","element","","","
","\r\n","","element2",""," \r\n");
$array = array_clean($array);
//$array[0] = "element";
//$array[1] = "element2";
NOTE: This trim()s it first, so it'll also strip lone spaces, newlines and the like.
----
Manual Page -- http://www.php.net/manual/en/ref.array.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34373
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34373&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34373&report=yes