What is the role of the array_search () function with 3rd parameters? Http://docs.php.net/manual/zh/function.array-search.phpmixed array_search (& nbsp array_search () function, 3rd parameters, what is the role?
Http://docs.php.net/manual/zh/function.array-search.php
mixed array_search ( mixed $needle , array $haystack [, bool $strict = false ] )
Strict
If the optional third parameter strict is TRUE, array_search () checks for identical elements in haystack. This means that the needle type in haystack is also checked, and the object must be the same instance.
Problem:
This function has 3rd parameters: $ strict = false. what is the function?
To an instance.
Share:
------ Solution --------------------
$ar = array(1, 2, 3);
var_dump(array_search('2', $ar, true)); //bool(false)
var_dump(array_search(2, $ar)); //int(1)
------ Solution --------------------
$ A = array ("a" => "5", "B" => 5 );
Echo array_search (5, $ a); no need to judge the value type, so the string "5" is matched successfully.
Echo'
';
Echo array_search (5, $ a, true); the value type must be determined. Therefore, the string "5" does not match successfully. the number 5 is matched successfully.