0

My var_dump displays NULL

Below is my code:

$dareas = rtrim($areas,",");
$areasinarray = explode($dareas);

var_dump($areasinarray);

As far as the $dareas is concerned, it is a string which values are 15,12,14,19

What is wrong with this code?

1
  • 2
    explode requires atleast 2 params.. syntactically wrong code. Commented Jan 7, 2014 at 10:14

5 Answers 5

2

You only supply the delimiter, not the string itself.

It should be

explode(",", $dareas);

Check out the documentation.

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

1 Comment

Oh yes! I keep missing the other delimeter. Thanks!
2

Try this. you were trying to explode without any delimiter

<?php
$areas = "15,12,14,19";
$dareas = rtrim($areas,",");
$areasinarray = explode(',', $dareas);

var_dump($areasinarray);

Comments

1

explode(); requires another parameter - the delimiter. See the manual. In your case that'd be a comma.

explode(',', $dareas);

Also, when developing, set error_reporting to E_ALL. That'll catch mistakes like this.

2 Comments

where can I set that?
Put it at the very top of your PHP file. error_reporting(E_ALL);
0

Do you mean:

$areasinarray = explode(',' ,$dareas);

Comments

0

Explode needs 2 parameters. The first is the delimiter("," in your case) and the second parameter has to be your string($dareas). Check http://be1.php.net/explode for more info.

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.