views:

51

answers:

3

Hi All,

I'm running a RegEx to match all instances of the Twitter hashtag. It returns it just fine, but now I just want to loop through the first set and return my #hello, #world, #hello-world....not the second set. Any help will be quickly rewarded!

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

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

)
+2  A: 

Specify $arr[0] as the array you want to iterate:

foreach ($arr[0] as $tag) {
    // …
}
Gumbo
+2  A: 

do you mean foreach($array[0] as $string) {...?

soulmerge
+1  A: 

You don't even need to loop through. You can just do

return $matches[0];

This will return

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