This shows you the differences between two versions of the page.
uphp:functions:explode [2021/02/02 10:13] admin |
uphp:functions:explode [2021/09/13 05:57] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ======explode====== | ||
- | |||
- | < | ||
- | |||
- | < | ||
- | |||
- | ====Description==== | ||
- | |||
- | <well size=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | </ | ||
- | < | ||
- | |||
- | ====Parameters==== | ||
- | |||
- | < | ||
- | |||
- | < | ||
- | |||
- | ====Return Values==== | ||
- | |||
- | < | ||
- | |||
- | ====Example==== | ||
- | |||
- | <code php> | ||
- | < | ||
- | $mylist=" | ||
- | $myarray=explode($mylist,"," | ||
- | print_r($myarray); | ||
- | ?></ | ||
- | </ | ||
- | |||
- | The above example will output: | ||
- | < | ||
- | [$myarray] = Array ( | ||
- | (string) [0] => one | ||
- | (string) [1] => two | ||
- | (string) [2] => three | ||
- | (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) | ||
- | | ||
- | </ | ||
- | |||
- | ====See Also==== | ||
- | |||
- | [[implode()]] - < | ||
- | |||
- | [[print_r()]] - Dump the contents of an < | ||
- | |||
- | [[sizeof()]] - Return the number of elements in an < | ||
- | |||
- | [[uphp: | ||
- | |||
- | ====Additional Information==== | ||
- | |||
- | Note that there is an important difference in the parameter order between mainline PHP and Wattmon uPHP. In the mainline PHP function the delimiter comes first, but in uPHP the < | ||
- | |||
- | < | ||
- | |||
- | < | ||
- | |||
- | Wattmon uPHP's parameter order is easier to remember and more consistent: | ||