我有一个字符串,里面有productID,它们的数量用逗号隔开
例如。2334(3)、2335(15)
我怎么能比使用爆炸物质爆炸更容易把它变成一个数组呢?我在RegExp上做得很糟糕,但我认为你可以懒得捕捉变量吗?
相似:$a2334 =3
发布于 2014-03-11 21:15:42
您可以使用:
if (preg_match_all('/(\d+)\((\d+)\)/', '2334(3),2335(15)', $matches)) {
$output = array_combine ( $matches[1], $matches[2] );
print_r($output);
}产出:
Array
(
[2334] => 3
[2335] => 15
)https://stackoverflow.com/questions/22336655
复制相似问题