From bc82525c95b42207160365d6c6743cce79a43c47 Mon Sep 17 00:00:00 2001 From: Steven Wittens Date: Fri, 29 Dec 2006 00:19:58 +0000 Subject: #24023 (follow up): Add API function for dealing with form API #options arrays. --- includes/form.inc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'includes') diff --git a/includes/form.inc b/includes/form.inc index 4c95ce22a..4aac8d1a9 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -941,6 +941,27 @@ function form_select_options($element, $choices = NULL) { return $options; } +/** + * Traverses a select element's #option array looking for the object that + * holds the given key. Returns FALSE if not found. As usual with functions + * that can return 0 or FALSE do not forget to use === and !== if needed. + * + * @param $element + * The select element. + * @param $key + * The key to look for. + * @return + * The index of the object that held the $key with some value, or FALSE. + */ +function form_get_option_key($element, $key) { + foreach ($element['#options'] as $index => $object) { + if (isset($object->option[$key])) { + return $index; + } + } + return FALSE; +} + /** * Format a group of form items. * -- cgit v1.2.3