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/04/12 12:54] jeff |
uphp:functions:explode [2021/09/13 05:57] (current) |
||
---|---|---|---|
Line 7: | Line 7: | ||
====Description==== | ====Description==== | ||
- | <well size=" | + | <well size=" |
- | < | + | |
<span style=" | <span style=" | ||
- | <span style=" | + | <span style=" |
- | </ | + | |
- | [[explode]] ( | + | |
- | < | + | |
<span style=" | <span style=" | ||
<span style=" | <span style=" | ||
Line 19: | Line 15: | ||
<span style=" | <span style=" | ||
<span style=" | <span style=" | ||
- | </ | + | </ |
- | </ | + | |
< | < | ||
Line 29: | Line 24: | ||
< | < | ||
- | ====Return | + | ====Return |
< | < | ||
Line 51: | 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) | ||
+ | ?></ | ||
</ | </ | ||