On Tuesday 02 November 2004 13:32, Merlin wrote:
I am retrieving some values out of the db and would only like to show those available inside a drop down field. Now I do have 2 arrays which fill the drop down field and one array with the values which should only show up.
Example: $objects_available = array(3,5,7);
$ob_options = array( 'all available', 'accomodations', 'internet access', 'tour operators', 'restaurants' , 'pubs', 'clubs', 'museums', 'secret spots', 'hotels at the airport');
$ob_values = array( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
Has anybody an idea how to filter just the ones out which are inside the objects available array? I am sure this is possible without any if statements, but just cant come up with a clear programming solution.
Assuming that '0' corresponds to 'all available', '1' to 'accomodations' etc, then:
foreach ($objects_available as $key) { echo $ob_options[$key]; }
This did not work.
Here is how I solved it:
$key = array_search($ob_values[$h], $object);
if ($key !== false)
printf ("<option value = \"%s\"%s>%s</option>\n", $ob_values[$h],$isselected,$ob_options[$h]);
Merlin
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php