3

Quoted from here:

If delimiter contains a value that is not contained in string and a negative limit is used, then an empty array will be returned, otherwise an array containing string will be returned.

But why I still don't get an empty array?

var_dump(explode(',', '', -1))

I get this:

array(1) {
  [0]=>
  string(0) ""
}

UPDATE

Try it in windows,with PHP 5.2.8 (cli) (built: Dec 8 2008 19:31:23)

7
  • 6
    What do you get? Commented Jul 22, 2010 at 7:41
  • 1
    What version of PHP are you running that on? Commented Jul 22, 2010 at 7:50
  • PHP 5.2.8 (cli) (built: Dec 8 2008 19:31:23) Commented Jul 22, 2010 at 7:51
  • why you are looking for empty array from such a expression? there is an easy way- $arr=array(); Commented Jul 22, 2010 at 7:51
  • I'm not looking for empty array,just spot a bug-alike stuff Commented Jul 22, 2010 at 7:53

3 Answers 3

1

I can confirm that this doesn't work in PHP 5.2.8.

It does work in PHP 5.2.11. In my opinion, there are many bugs in the 5.2 branch, so try always to use the latest version. 5.3 is more stable in my experience.

Sign up to request clarification or add additional context in comments.

Comments

0

I've tried this example and got empty array. Wrong question.

2 Comments

Trurl, it results array(1) { [0]=> string(0) "" } which is non-empty
Please use latest PHP version. May be this is a bug
0

Tested your code, and it does return an empty array: array(0) { }.
Running PHP 5.2.11.

Maybe there's an issue with your PHP version. Can you tell us which one you are running?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.