You are here

function webform_compare_select in Webform 7.4

Utility function to compare values of a select component.

Parameters

string $a: First select option key to compare.

string $b: Second select option key to compare.

array $options: Associative array where the $a and $b are within the keys.

Return value

int|null Based upon position of $a and $b in $options: -N if $a above (<) $b 0 if $a = $b +N if $a is below (>) $b

4 calls to webform_compare_select()
webform_conditional_operator_select_greater_than in includes/webform.conditionals.inc
Conditional callback for select comparisons.
webform_conditional_operator_select_greater_than_equal in includes/webform.conditionals.inc
Conditional callback for select comparisons.
webform_conditional_operator_select_less_than in includes/webform.conditionals.inc
Conditional callback for select comparisons.
webform_conditional_operator_select_less_than_equal in includes/webform.conditionals.inc
Conditional callback for select comparisons.

File

includes/webform.conditionals.inc, line 1773
Form elements and menu callbacks to provide conditional handling in Webform.

Code

function webform_compare_select($a, $b, array $options) {

  // Select keys that are integer-like strings are numeric indices in PHP.
  // Convert the array keys to an array of strings.
  $options_array = array_map(function ($i) {
    return (string) $i;
  }, array_keys($options));
  $a_position = array_search($a, $options_array, TRUE);
  $b_position = array_search($b, $options_array, TRUE);
  return $a_position === FALSE || $b_position === FALSE ? NULL : $a_position - $b_position;
}