note 114273 deleted from function.explode by salathe
| From: | salathe@php.net | Date: | Mon, 21 Sep 2020 14:49:04 +0000 |
| Subject: | note 114273 deleted from function.explode by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-215325@lists.php.net to get a copy of this message | ||
Note Submitter: artaxerxes2 at iname dot com
----
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