How does an array search be case insensitive?

Source: Internet
Author: User
How does an array search be case insensitive?
Why the following 2 are not searched Ah, I read the manual said add a false can, why not yet?

PHP Code
  
   
  
   


------Solution--------------------
If needle is a string, the comparison is case-sensitive.
If the value of the third parameter strict is TRUE then the In_array () function also checks whether the needle type is the same as in haystack.


------Solution--------------------
In_array

Optional. If set to true, checks whether the searched data is the same as the type of the array's value.

Whether the type of the value is the same is not case-sensitive

Array_search

If the third parameter, strict, is specified as true, the key name of the corresponding element is returned only if the data type and value are consistent.

is also a type and value, and does not mention case-sensitive things.

According to your needs

1. Traversal using a string comparison function
2. Regular
3. Convert all to lowercase after comparison
....

------Solution--------------------
The third parameter is the type of judgment, which is the use of = = =, not = =.

A function to traverse the line.
------Solution--------------------
Trouble yourself to see php.net, this basic problem you will meet hundreds of thousands, you ask?
------Solution--------------------
Explore

Reference:

If needle is a string, the comparison is case-sensitive.
If the value of the third parameter strict is TRUE then the In_array () function also checks whether the needle type is the same as in haystack.

I would like to ask under what circumstances is the In_array function case insensitive?
I change to an array or case-sensitive.
$DR =array (' cc ', ' Dd ', ' Ee ');
$VR =arr ...

------Solution--------------------
Just write one yourself.
PHP Code
$DR = Array (' CC ', ' dd ', ' Ee '), if (In_iarray ("Dd", $dr, False)) {    echo "AA";} function In_iarray ($needle, $haystack, $strict =false) {  if (! is_string ($needle)) return In_array ($needle, $ haystack, $strict);  Return In_array (Strtolower ($needle), Array_map (' Strtolower ', $haystack));}
  • Related Article

    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.