note 112155 modified in function.array-filter by googleguy
| From: | googleguy@php.net | Date: | Fri, 10 May 2013 14:17:40 +0000 |
| Subject: | note 112155 modified in function.array-filter by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-194775@lists.php.net to get a copy of this message | ||
If you need this function to return falsy results (like "0"), yet discard truly empty ones
(that have a 0 string length, like null, false, ''), you can use strlen() as the callback:
<?php
array_filter($array, 'strlen');
?>
--was--
If you need this function to return falsy results (like "0"), yet discard truly empty ones
(that have a 0 string length, like null, false, ''), you can use strlen() as the callback:
<?php
array_filter($array, 'strlen');
?>
Another option is to use the ord() as the callback, which should be ~7-8% faster on average (because
it only uses the first character).
http://php.net/manual/en/function.array-filter.php