$text = 'Lorem Ipsum'; $re = '/(?<AA>Any)|(?<BB>Lorem)/ui'; $nMatches = preg_match_all($re, $text, $aMatches);
$aMatches
будет содержать следующее:
Array ( [0] => Array ( [0] => Lorem ) [AA] => Array ( // do not include to result matches array [0] => // because have not match for this part ) [1] => Array ( [0] => ) [BB] => Array ( [0] => Lorem ) [2] => Array ( [0] => Lorem ) )
Вопрос: Возможно ли вернуть массив без узлов для именованных частей, которые не имеют совпадений?
Array ( [0] => Array ( [0] => Lorem ) {there was [AA] && [1], but have not returned because empty} [BB] => Array ( [0] => Lorem ) [1] => Array ( // changed to 1 [0] => Lorem ) )