note 36397 deleted from ref.array by sniper
| From: | sniper@php.net | Date: | Sat, 18 Oct 2003 17:59:41 +0000 |
| Subject: | note 36397 deleted from ref.array by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-58816@lists.php.net to get a copy of this message | ||
Note Submitter: ignacio paz posse
----
This is the optimization function (thanks to the guy that posted it on 12-Feb-2003) for removing
empty values of an array that I've rewritten to gain speed. It's twice faster if we just
use it like this:
function arryOpt(&$array) // pass by reference
{
if(!is_array($array)) return false;
$temp=array();
foreach($array as $v) { if(!empty($v)) $temp[]=$v; }
$array=$temp;
return true;
}
Moreover, (contrary to what I believed) the version of passing it by value behaves even (a litle)
faster.
function arryOpt($array) // pass by value
{
if(!is_array($array)) return false;
$temp=array();
foreach($array as $v) { if(!empty($v)) $temp[]=$v; }
$array=$temp;
return $array;
}