note 114931 added to function.array-filter
| From: | marc dot gray at gmail dot com | Date: | Tue, 29 Apr 2014 10:44:45 +0000 |
| Subject: | note 114931 added to function.array-filter | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-199368@lists.php.net to get a copy of this message | ||
My favourite use of this function is converting a string to an array, trimming each line and
removing empty lines:
<?php
$array = array_filter(array_map('trim', explode("\n", $string)),
'strlen');
?>
Although it states clearly that array keys are preserved, it's important to note this includes
numerically indexed arrays. You can't use a for loop on $array above without processing it
through array_values() first.
----
Server IP: 72.52.91.14
Probable Submitter: 195.99.205.98
----
Manual Page -- http://php.net/manual/en/function.array-filter.php
Edit -- https://master.php.net/note/edit/114931
Del: integrated -- https://master.php.net/note/delete/114931/integrated
Del: useless -- https://master.php.net/note/delete/114931/useless
Del: bad code -- https://master.php.net/note/delete/114931/bad+code
Del: spam -- https://master.php.net/note/delete/114931/spam
Del: non-english -- https://master.php.net/note/delete/114931/non-english
Del: in docs -- https://master.php.net/note/delete/114931/in+docs
Del: other reasons-- https://master.php.net/note/delete/114931
Reject -- https://master.php.net/note/reject/114931
Search -- https://master.php.net/manage/user-notes.php