3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str1 = 'key1:val1;key2:val2;key3:val3'; $str2 = 'key1:val1;key2:val2;key3:val3;'; function to_arr($str){ $array = array(); preg_match_all('/(.*?):(.*?);/',$str,$matches); foreach($matches[1]as$key=>$val){ $array[$val] = $matches[2][$key]; } return($array); } $arr1 = to_arr($str1); $arr2 = to_arr($str2); print_r($arr1); print_r($arr2);

preferences:
30.77 ms | 405 KiB | 5 Q