note 13998 deleted from function.explode by jimw
| From: | jimw@php.net | Date: | Fri, 07 Dec 2001 21:24:36 +0000 |
| Subject: | note 13998 deleted from function.explode by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-22007@lists.php.net to get a copy of this message | ||
When setting the LIMIT, you need to
start with 2, not 1. 1 has no effect
at all. The limit is NOT the number of
splits (i.e. the number of times you
split), but rather the number of pieces
left AFTER the split. This might be
a useful point to add into the docs
here and for split() too if applicable.
Most people probably figure it out,
but it's somewhat counter-intuitive.
I guess I'm slow.
Thus this code:
$string = "cats_dogs_mice";
$array = explode ("_", $string, 1)
Results in this array which has clearly
not exploded the string:
$array[0] = "cats_dogs_mice"
The proper way to explode out the first
element ("cats) would be:
$string = "cats_dogs_mice";
$array = explode ("_", $string, 2)
Which would produce:
$array[0] = "cats";
$array[1] = "dogs_mice";
Usually, when working with counting,
programmers have to start with zero,
rather than one as we were taught in
first grade.
Here though, we have to start counting
with two. :-)