RegEx 有点问题, 我有琴弦
AM.name:ASC,AMAdvanced.start:DESC,
AMAdvanced.start:DESC,AM.Genre:Action
需要将它们分解成
array(0){
AM.name => ASC,
AMAdvanced.start => DESC
}
and
array(0){
AMAdvanced.start => DESC,
AM.Genre => Action
}
任何帮助都会很棒,因为对正则表达式是全新的
最佳答案
这里不需要regex
。
步骤:
用逗号分解
,
- 遍历展开的
数组
Explode
冒号:
- 插入新的
数组
代码:
$newArr = array();
foreach (explode(',', trim($str, " ,")) AS $el) {
$el = explode(':', $el);
$newArr[$el[0]] = $el[1];
}
print_r($newArr);
关于php - 正则表达式数组与字符串问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30965506/