note 29406 deleted from ref.array by sniper
| From: | sniper@php.net | Date: | Sat, 18 Oct 2003 18:02:13 +0000 |
| Subject: | note 29406 deleted from ref.array by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-58830@lists.php.net to get a copy of this message | ||
Note Submitter: telefoontoestel@officexpert.digitaal.biz
----
I've created a small function for the optimization of an array. It removes all empty elements
and sets the next filled element to the place the empty element was. It is a function wich argument
is passed by reference, so it will only return true, in case the value of the argument was correct
or false if the value was incorrect.
function arOpt(&$array){ // pass by reference
if(!is_array($array)){
return false;
}
$temp; // create a temporary array;
for($i = 0; $i < sizeof($array); $i++){
if(!empty($array[$i])){
$temp[sizeof($temp)] = $array[$i];
}
}
$array = $temp;
return true;
}