Skip to content
Advertisement

Explode/Implode in foreach loop

I have a list of strings like

JavaScript

I use explode on this list to get the list items as an array:

JavaScript

Now I need to take each item of the array and pass it to an API one by one and the API will return the IDs for the list entries. I want to end up with a string that is just like $list but with the IDs instead of the strings. My problem is that I can’t pass an array to the API funtion. I need to do it for every single list item. So I’m looping through the array:

JavaScript

If I run this code the result is: 3;4; Which is exactly what I need to pass it to another API function. But when I need to re-use this list outside of the loop . If I then use $AssignedGroups I only get the last ID, not the 2 (or more) merged ones.

What am I doing wrong?

Here is the complete code for reference:

JavaScript

Advertisement

Answer

What really should be done here:

JavaScript

Fiddle with implode example.

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