0

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.

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

3 Answers 3

3

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

foreach ($arr[0] as $tag) { // … } 
Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

1

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 ) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.