note 111650 added to function.explode

From: Date: Tue, 12 Mar 2013 21:13:51 +0000
Subject: note 111650 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-194046@lists.php.net to get a copy of this message
The comments to use array_filter() without a callback to remove empty strings from explode's results miss the fact that array_filter will remove all elements that, to quote the manual, "are equal to FALSE". This includes, in particular, the string "0", which is NOT an empty string. If you really want to filter out empty strings, use the defining feature of the empty string that it is the only string that has a length of 0. So: <?php array_filter(explode(':', "1:2::3:0:4"), 'strlen'); ?> ---- Server IP: 69.147.83.199 Probable Submitter: 202.175.135.150 ---- Manual Page -- http://php.net/manual/en/function.explode.php Edit -- https://master.php.net/note/edit/111650 Del: integrated -- https://master.php.net/note/delete/111650/integrated Del: useless -- https://master.php.net/note/delete/111650/useless Del: bad code -- https://master.php.net/note/delete/111650/bad+code Del: spam -- https://master.php.net/note/delete/111650/spam Del: non-english -- https://master.php.net/note/delete/111650/non-english Del: in docs -- https://master.php.net/note/delete/111650/in+docs Del: other reasons-- https://master.php.net/note/delete/111650 Reject -- https://master.php.net/note/reject/111650 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#194046) next »