$text = 'Lorem Ipsum';
$re = '/(?<AA>Any)|(?<BB>Lorem)/ui';
$nMatches = preg_match_all($re, $text, $aMatches);
$aMatches
will contain the following:
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
)
)
Question: Is it possible to return the array without nodes for named parts that have no matches?
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
)
)