Hello All, Please help me in below problem. I have an string like below: $str="'apple','orange','mango'"; I want to create above string into an array $ary=array($str); When I run the code it's output like below. print_r($ary); Array ( [0] => 'apple','orange','mango' ) But I want the output like below so i can loop my array. Array ( [0] => apple [1] => oraange [2] => mango ) Please help me on this , I have tried lot's of things but not worked for me. Thanks in advance .
Try this: <?php $str="'apple','orange','mango'"; $ary=explode("','", substr($str, 1, -1)); print_r($ary); ?> PHP:
Try this... <?php $str="'apple','orange','mango'"; //removes the tick marks from string $str = str_replace("'", "", $str); //splits string into array $myArry = explode(",", $str); print_r($myArry); ?> Code (markup): Hope this helps!