Search code examples
phparrayssplittext-parsing

Parse array element containing comma-separated and quoted strings to generate a new array of elements


Now my array is Storing values like

Array([0] => "Aaa", "bbb", "ccc")

How can I make this Array as below using PHP

Array[0] = "Aaa", Array[1] = "bbb", Array[2] = "ccc"

How to make like this. I tried with explode its not taking values correctly.


Solution

  • $oldarray[0]='"abc","def","hij"';
    $oldarray[1]='"abc","def","hij"';
    $newarray=array();
    foreach ($oldarray as $value) {
        $newarray[] = str_replace('"','',explode(',',$value));
        //print_r($value);die();
    }
    print_r($newarray);