Re: Arrays: Comma at end?
| From: | Ashley Sheridan | Date: | Tue, 07 Feb 2012 20:32:44 +0000 |
| Subject: | Re: Arrays: Comma at end? | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-316546@lists.php.net to get a copy of this message | ||
On Tue, 2012-02-07 at 12:26 -0800, Micky Hulse wrote:
> On Tue, Feb 7, 2012 at 12:19 PM, Micky Hulse <rgmicky@gmail.com> wrote:
> > Yah, ditto! :D
>
> $s = 'foo,bar,';
> print_r(explode(',', $s));
>
> The output is:
>
> Array
> (
> [0] => foo
> [1] => bar
> [2] =>
> )
>
> That's one instance where I know you have to be cautious about the
> trailing delimiter.
>
> I know, this is all noob stuff... Sorry. :D
>
That's because it's not an array you've got the trailing delimiter on,
it's a string. We were talking about commas on the end of the last
element in the array, like:
$var = array(
'foo',
'bar',
);
That only contains two elements, and won't have a hidden 3rd at any
time.
--
Thanks,
Ash
http://www.ashleysheridan.co.uk