Having a little issue with RegEx, I have the strings
AM.name:ASC,AMAdvanced.start:DESC,
AMAdvanced.start:DESC,AM.Genre:Action
and need to break them into
array(0){
AM.name => ASC,
AMAdvanced.start => DESC
}
and
array(0){
AMAdvanced.start => DESC,
AM.Genre => Action
}
Any help would be fantastic since completely new to regex
No need of regex here.
Steps:
explode by comma ,arrayExplode by colon :arrayCode:
$newArr = array();
foreach (explode(',', trim($str, " ,")) AS $el) {
$el = explode(':', $el);
$newArr[$el[0]] = $el[1];
}
print_r($newArr);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With