我有两个 preg_match() 调用,我想合并数组而不是替换第一个数组。到目前为止我的代码:
$arr = Array();
$string1 = "Article: graphics card";
$string2 = "Price: 300 Euro";
$regex1 = "/Article[\:] (?P<article>.*)/";
$regex2 = "/Price[\:] (?P<price>[0-9]+) Euro/";
preg_match($regex1, $string1, $arr);
//output here:
$arr['article'] = "graphics card"
$arr['price'] = null
preg_match($regex2, $string2, $arr);
//output here:
$arr['article'] = null
$arr['price'] = "300"
我该如何匹配,所以我的输出将是:
$arr['article'] = "graphics card"
$arr['price'] = "300"
?