Thursday, December 12, 2013

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.
$strings =  "my, name, is, Anup";
$arraydata = explode(",", trim($strings));
echo '$arr = array("'.implode('", "', $arraydata).'");';
// $arr = array("my", "name", "is", "Anup");

No comments:

Post a Comment