سؤال

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?

هل كانت مفيدة؟

المحلول

You only supply the delimiter, not the string itself.

It should be

explode(",", $dareas);

Check out the documentation.

نصائح أخرى

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);

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.

Do you mean:

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

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top