Problem with array_search and IF condition in PHP

Warning message

JQuery Cycle must be installed in order to run the slideshow. Please go to Status Report for instructions.

Primary tabs

Sometimes we use array_search for finding the value present in array and get the place(key) of that value. It is good to use that unless you are using the array which starts from 0th position . As array search returns the KEY of the matched value. Suppose if the Key if present on 0th position, then key is returned as 0 in the IF condition and IF understand 0 as FALSE, so that condition will never be executed because it will never pass the condition .

Solution : Use is_numeric() function inside the IF condition, so even the array_search functions returns 0, it will be still treated as TRUE by is_numeric.

For example :

/* Process IF condition on 0th key if evaluates TRUE */
  if (is_numeric($key = array_search($value_to_search, $array_to_search))) {
         // Your logic