Skip to content
Advertisement

Extract values from one row string for foreach

I extracted two inputed usernames from a text string with @ mention tag.

Now I want to put them in foreach loop so I can use my doctrine instance to search for their user name.

My code:

JavaScript

The result I get:

“john”, “jane”

I can’t find a way to extract them so I can use one by one in foreach loop.

So my try is: (update: working solution)

JavaScript

Advertisement

Answer

As usernames[1] is already an array you can iterate over it:

JavaScript

And as doctrine supports where in () clause in findBy you can use this array without foreach:

JavaScript

You can modify this code as needed.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement