This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
uphp:functions:explode [2017/05/11 22:47] jeff |
uphp:functions:explode [2021/09/13 05:57] (current) |
||
---|---|---|---|
Line 46: | Line 46: | ||
(string) [3] => four | (string) [3] => four | ||
) | ) | ||
+ | ?></ | ||
+ | </ | ||
+ | |||
+ | Note that if only one element is present (without the separator character) then a value of -1 will be returned. | ||
+ | |||
+ | <code php> | ||
+ | < | ||
+ | $mylist=" | ||
+ | $myarray=explode($mylist,"," | ||
+ | | ||
+ | // the fix for a single parameter is to use is_array | ||
+ | if (!is_array($myarray)) { | ||
+ | $myarray=array($mylist); | ||
+ | } | ||
+ | print_r($myarray) | ||
+ | ?></ | ||
</ | </ | ||