2010-02-22 202 views
0

我正在運行RegEx以匹配Twitter標籤的所有實例。它返回它就好了,但現在我只想循環第一組並返回我的#hello,#world,#hello-world ....而不是第二組。任何幫助將很快得到回報!陣列Foreach循環

Array 
(
    [0] => Array 
     (
      [0] => #hello 
      [1] => #world 
      [2] => #hello-world 
     ) 

    [1] => Array 
     (
      [0] => hello 
      [1] => world 
      [2] => hello-world 
     ) 

) 

回答

3

指定$arr[0]只要你想遍歷數組:

foreach ($arr[0] as $tag) { 
    // … 
} 
2

你的意思foreach($array[0] as $string) {...

1

你甚至不需要循環。 你可以做

return $matches[0]; 

這將返回

Array (
     [0] => #hello 
     [1] => #world 
     [2] => #hello-world 
    )