我正在运行正则表达式来匹配 Twitter 主题标签的所有实例。它返回得很好,但现在我只想循环第一组并返回我的
#hello, #world, #hello-world
,而不是第二组。
Array
(
[0] => Array
(
[0] => #hello
[1] => #world
[2] => #hello-world
)
[1] => Array
(
[0] => hello
[1] => world
[2] => hello-world
)
)
指定
$arr[0]
作为要迭代的数组:
foreach ($arr[0] as $tag) {
// …
}
你的意思是
foreach($array[0] as $string) {...
吗?
您甚至不需要循环。 你就可以做
return $matches[0];
这会回来
Array (
[0] => #hello
[1] => #world
[2] => #hello-world
)