Hi Im struggling with the merge command while looping through image data.
I am trying to extract the ‘tags’ associated with each image (which I have managed - converting from a string into an array) then add all these ‘tags’ together in one ‘big’ array which I want to used to display a list of ALL the tags used.
There’s not enough code there to know what is wrong. For one, you need to have $array_big defined as an array before using it in array_merge. Also what is the point of the foreach when you just do $str=$tags on each iteration.
Ok. I think I need to break it down. Here is were I am. This connects to the API (Slideshow Pro Director API) then requests info for all images. I then loop through each image to display the data.
Well foreach makes sense if it’s $images->tags. I don’t know what you’re doing wrong, or even what your error/problem is, but this works, hope it helps
$tags = array('one two three', 'four five six');
$big_array = array(); // needs to be defined
foreach($tags as $t) {
$array = explode(' ', $t);
$big_array = array_merge($big_array, $array);
}
/*
Array
(
[0] => one
[1] => two
[2] => three
[3] => four
[4] => five
[5] => six
)
*/
We eliminate all empty array members with array_filter ;). That particular line ensures that the tag in question is not already in our collection, thereby ensuring unique entries.