Create Array Without Keys From Comma Separated String Using PHP

You can't have an array without keys. But there is workaround to make it possible.
Grab the comma separated string and use explode function to create array. Use the implode function on resulting array, and you will get the nice array without keys.
Example
$strings =  "my, name, is, Anup";
$arraydata = explode(",", trim($strings));
echo '$arr = array("'.implode('", "', $arraydata).'");';
//output 
// $arr = array("my", "name", "is", "Anup");

Comments

Popular Posts