PHP array - explode some comma separated elements into new items -
how can take array individual strings comma separated strings , explode comma separated items individual items? instance:
while(($row = mysql_fetch_array($downloads_query))) { $product_array[] = $row['product']; }
$product_array[]
returns:
item 1: "10003" item 2: "10016" item 3: "10008, 10007, 10010"
how can split item 3 individual items 3, 4 , 5 $product_array returns:
item 1: "10003" item 2: "10016" item 3: "10008" item 4: "10007" item 5: "10010"
while(($row = mysql_fetch_array($downloads_query))) { if(strpos($row['product'],',') > -1){ $product_array += explode(',',$row['product']); } else { $product_array[] = $row['product']; } }
here fast solution :) if there comma explode before adding array.
- as other people notice myslq_ functions deprecated .. better use mysqli or pdo instead :)
Comments
Post a Comment