note 46531 added to function.trim
| From: | rubbish at garbage dot com | Date: | Thu, 14 Oct 2004 10:26:05 +0000 |
| Subject: | note 46531 added to function.trim | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-78533@lists.php.net to get a copy of this message | ||
It's not, the forach way is about 4.5 times faster than your other method. Use this code to
compare :
<?
for( $i=0; $i<10000; $i++ ) {
$db[$i] = " dskjdskjdlskjdlskjldskdjslkjd ";
}
echo microtime()."\n";
array_walk($db ,create_function('&$arr','$arr=trim($arr);'));
echo microtime()."\n\n\n";
for( $i=0; $i<10000; $i++ ) {
$db[$i] = " dskjdskjdlskjdlskjldskdjslkjd ";
}
echo microtime()."\n";
foreach ($db as $key=>$value) { $db[$key]=trim($value); }
echo microtime()."\n";
?>
----
Manual Page -- http://www.php.net/manual/en/function.trim.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46531
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46531&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46531&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46531&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46531&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46531&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46531&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46531&report=yes
Search -- http://master.php.net/manage/user-notes.php