note 114273 added to function.explode

From: Date: Fri, 31 Jan 2014 16:30:00 +0000
Subject: note 114273 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-198376@lists.php.net to get a copy of this message
Note that using explode() on an empty string returns a non-empty array. So the code: <?php print_r(explode("|",""); ?> returns: Array ( [0] => ) If you need to return an empty array in the case of an empty string, you must call array_diff() after the explode: <?php print_r(array_diff(explode("|",""),array(""))); ?> returns: Array ( ) This is useful in case your use of MySQL's group_concat() returns an empty string for just some records but you want to convert them all to arrays that actually reflect what group_concat() gave you ---- Server IP: 72.55.140.6 Probable Submitter: 209.202.82.139 ---- Manual Page -- http://php.net/manual/en/function.explode.php Edit -- https://master.php.net/note/edit/114273 Del: integrated -- https://master.php.net/note/delete/114273/integrated Del: useless -- https://master.php.net/note/delete/114273/useless Del: bad code -- https://master.php.net/note/delete/114273/bad+code Del: spam -- https://master.php.net/note/delete/114273/spam Del: non-english -- https://master.php.net/note/delete/114273/non-english Del: in docs -- https://master.php.net/note/delete/114273/in+docs Del: other reasons-- https://master.php.net/note/delete/114273 Reject -- https://master.php.net/note/reject/114273 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#198376) next »