From the PHP documentation:
So, $ out [0] contains array of strings that matched full pattern, and $ out [1] contains array of strings enclosed by tags.
This means that in its variable $output_array
the index 0
represents an array of strings containing the values found that close with the complete regular expression. Already in the index 1
is another array of strings containing the values found that close with the expressions delimited by tags (the parentheses).
For example, see the code below.
preg_match_all("/.*(World).*/", "Hello World", $out);
The result of $out
will be:
Array (
[0] => Array (
[0] => Hello World
)
[1] => Array (
[0] => World
)
)
Finally, what you want is to go through the array that closes with the complete expression.
foreach($output_array[0] as $word) {
echo $word;
}