The array_search () function has 3rd parameters. what is the function?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.