How to create array from comma separated string in php

Often times when coding in PHP, we have the need to turn an array into a comma separated string.

try using explode function

$string = "user,admin,superadmin";
$array = explode(',', $string);
print_r($array);

Output

Array
(
    [0] => user
    [1] => admin
    [2] => superadmin
)

Leave a Reply

Your email address will not be published. Required fields are marked *