You are here

public static function ArrayUtils::inArray in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-stdlib/src/ArrayUtils.php \Zend\Stdlib\ArrayUtils::inArray()

Checks if a value exists in an array.

Due to "foo" == 0 === TRUE with in_array when strict = false, an option has been added to prevent this. When $strict = 0/false, the most secure non-strict check is implemented. if $strict = -1, the default in_array non-strict behaviour is used.

Parameters

mixed $needle:

array $haystack:

int|bool $strict:

Return value

bool

File

vendor/zendframework/zend-stdlib/src/ArrayUtils.php, line 188

Class

ArrayUtils
Utility class for testing and manipulation of PHP arrays.

Namespace

Zend\Stdlib

Code

public static function inArray($needle, array $haystack, $strict = false) {
  if (!$strict) {
    if (is_int($needle) || is_float($needle)) {
      $needle = (string) $needle;
    }
    if (is_string($needle)) {
      foreach ($haystack as &$h) {
        if (is_int($h) || is_float($h)) {
          $h = (string) $h;
        }
      }
    }
  }
  return in_array($needle, $haystack, $strict);
}