PHP Array function correlation

Source: Internet
Author: User

The PHP array function is a key point, because in PHP is a major composite data type,

The first is to look for a value whether there is a function in an array:

array_search- searches for the given value in the array, and returns the corresponding key name if successful

mixed array_search ( mixed $needle , array $haystack [, bool $strict ])
<?php$array = Array (0 = ' Blue ', 1 = ' red ', 2 = ' green ', 3 = ' red '); $key = Array_search (' green ', $array) ; $key = 2; $key = Array_search (' red ', $array);   

If you need to relate to TRUE or false, use this function with caution, because if the first bit of the value is satisfied, it is possible to return the key value 0, which is false, it does not set

in_array- Checks if a value exists in the array

BOOL In_array ( mixed $needle , array $haystack [, bool $strict ])

<?php$os = Array ("Mac", "NT", "Irix", "Linux"), if (In_array ("Irix", $os)) {    echo "Got Irix";} if (In_array ("Mac", $os)) {    

The occasional problem with this function is a case-sensitive problem,

Array_key_existsbool array_key_exists ( mixed $key , array $search )
<?php$search_array = Array (' first ' = = 1, ' second ' = 4); if (array_key_exists (' first ', $search _array)) {    echo "The ' first ' element is in the array";}? >

PHP Array function correlation

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.