Populating drop down dynamically
Permalink
Hello,
I have a drop-down search field that is being populated using API and xml. This works fine, apart from the fact that I can't seem to get rid of repeated elements. For example, the code below retrieves the 'activity' of a tour. But more than one tour is, lets say, 'kayaking' so I end up with a drop-down that has 'kayaking' listed multiple times.
I only need to list this activity once.
I've tried using 'unique_array' as well as many other things with no luck.
Any ideas very much appreciated
I have a drop-down search field that is being populated using API and xml. This works fine, apart from the fact that I can't seem to get rid of repeated elements. For example, the code below retrieves the 'activity' of a tour. But more than one tour is, lets say, 'kayaking' so I end up with a drop-down that has 'kayaking' listed multiple times.
I only need to list this activity once.
I've tried using 'unique_array' as well as many other things with no luck.
Any ideas very much appreciated
<select name="Activity" value=""> <option disabled selected> -- Select activity -- </option> <?php foreach ($search->tour as $tour){ $activities = $tour->xpath('custom1'); foreach (array_unique($activities) as $activity) { ?> <option value="<?php echo $activity; ?>"><?php echo $activity; ?></option> <?php }}?> </select>