I need to print all matches using preg_match_all.
$search = preg_match_all($pattern, $string, $matches); foreach ($matches as $match) { echo $match[0];
You could loop recursively. This example requires SPL and PHP 5.1+ via RecursiveArrayIterator:
foreach( new RecursiveArrayIterator( $matches ) as $match ) print $match;