Explode a string with key => value pair

Explode a string with key => value pair

$string = ‘200AUD, 150USD, 80GBP, 1250000VND’;
$array1 = explode(‘,’, $string);
$array2 = array();
foreach($array1 as $string){
$currency = preg_replace(“/[0-9]+/”, “”, $string);
$value = preg_replace(“/[a-zA-Z]+/”, “”, $string);
$array2[$currency] = $value;
}
print_r($array2);

Leave a comment