php-src

php in_array的坑以及其实现

先来看一段代码 <?php $array = ["a", "b", "c"]; var_dump(in_array(0, $array)); 这东西的输出是true, 虽然数组里并没有0 $array = ["a", "b", "c"]; var_dump(in_array(0, $array, true)); 这东西的输出是false!!! 文档 http://php.net/manual/en/function.in-array.php 很简单没啥可说的 in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] ) : bool 源码 https://github.com/php/php-src/blob/master/ext/standard/array.c /* {{{ proto bool in_array(mixed needle, array haystack [, bool strict]) Checks if the given value exists in the array */ PHP_FUNCTION(in_array) { php_search_array(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); } /* ...
执行时间: 1710840624986.4 毫秒