Search code examples
phparraysstringvar-dump

PHP var_dump is displaying NULL when using explode function


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?


Solution

  • You only supply the delimiter, not the string itself.

    It should be

    explode(",", $dareas);
    

    Check out the documentation.