I have a info which is stored in a string like:
id1:234,id3:23443,id32:andson
I want to split the string with one regex but so that i get the pairs split to like in an array
array(id1=>234, id3=>s3443...)
Is there a way to do that?
I have a info which is stored in a string like:
id1:234,id3:23443,id32:andson
I want to split the string with one regex but so that i get the pairs split to like in an array
array(id1=>234, id3=>s3443...)
Is there a way to do that?
Option 1:
$string = 'id1:234,id3:23443,id32:andson';
preg_match_all('/([^,:]+)\:([^,:]+)/', $string, $matches);
$result = array_combine($matches[1], $matches[2]);
Option 2:
$string = 'id1:234,id3:23443,id32:andson';
parse_str(str_replace([':', ','], ['=', '&'], $string), $result);