Split a string with two delimiters into two arrays (explode twice)

You can explode the string by commas, and then explode each of those values by x, inserting the result values from that into the two arrays: $str = “20×9999,24×65,40×5”; $array1 = array(); $array2 = array(); foreach (explode(‘,’, $str) as $key => $xy) { list($array1[$key], $array2[$key]) = explode(‘x’, $xy); } Alternatively, you can use preg_match_all, matching … Read more