Forum Moderators: coopster
$BB_Basket = "basket=¦APL6007,2.00¦AVX8900,1.00¦ARCAV500,1.00";
$basket_containers = explode('¦', $BB_Basket);
unset($basket_containers[0]);
print_r($basket_containers);
This results in
Array ( [1] => APL6007,2.00 [2] => AVX8900,1.00 [3] => ARCAV500,1.00 )
Now when I try to explode further with
$basket_items = explode(',', $basket_containers);
print_r($basket_items);
This results in
Array ( [0] => Array )
This should result in a 6 item array. Any ideas what I'm doing wrong?
$BB_Basket = "basket=¦APL6007,2.00¦AVX8900,1.00¦ARCAV500,1.00";
$pattern = "/[¦,]/";
echo '<pre>';
print_r([url=http://www.php.net/preg-split]preg_split[/url]($pattern,$BB_Basket));
echo '</pre>';
Note: If you copy and paste the code, remember to replace the pipe character (¦) with a solid one.
Good luck! :)
explode [php.net] takes a string as a parameter, not an array. You were passing it an array and it basically wasn't doing anything with it.
To use explode, you would either have to loop through each element in the array, explode each, and then push each of those values onto another array - or - you could explode the original with ¦ as the separator, then implode the results of that with a comma, and then explode it again with a comma as the separator; way too much work! A nice preg_split does the trick nicely :)