1
我正在做一個preg_match
命名捕獲組。當我打印出的$matches
它顯示了命名組,也是默認索引組,就像這樣:不保存索引捕獲的組,只是命名的捕獲組
Array
(
[0] => placeholder/placeholder2
[p1] => placeholder <-- Named, good
[1] => placeholder <-- Indexed, don't want this
[p2] => placeholder2 <-- Named, good
[2] => placeholder2 <-- Indexed, don't want this
)
隨着這段代碼:
$str = 'placeholder/placeholder2';
preg_match('#(?P<p1>[[:alnum:]]+)/(?P<p2>[[:alnum:]]+)#', $str, $matches);
echo '<pre>';
print_r($matches);
echo '</pre>';
我只想要在我的$matches
結果中擁有指定的組。我怎樣才能避免它作爲索引組保存比賽?