How can I avoid case sensitivity when searching arrays?

Source: Internet
Author: User
How can I make array search case insensitive? Why can't I find either of the following two items? I read the manual and said that adding false is acceptable. why not? PHPcode & lt ;? Php $ dr = array ('CC', 'DD', 'ee '); if (in_array (& quot; Dd & quot;, $ dr, how can I make the fal array search case insensitive?
Why can't I find either of the following two items? I read the manual and said that adding false is acceptable. why not?

PHP code
  
  


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


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

Optional. If this parameter is set to true, check whether the data to be searched is of the same type as the value of the array.

Whether the values are of the same type is not case sensitive

Array_search

If the third parameter strict is set to true, the key name of the corresponding element is returned only when the data type and value are consistent.

It is also a type and value, and case sensitivity is not mentioned.

Based on your needs

1. use string comparison functions for traversal
2. Regular expression
3. convert all to lowercase before comparison
....

------ Solution --------------------
The third parameter is the judgment type, that is, using =, rather than = ..

Function traversal.
------ Solution --------------------
Let's take a look at php.net on your own. are you going to ask hundreds of basic questions?
------ Solution --------------------
Discussion

Reference:

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

I would like to ask when the in_array function is case insensitive?
Replace it with an array or case sensitive.
$ Dr = array ('CC', 'DD', 'ee ');
$ Vr = arr ......

------ Solution --------------------
Write one by 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));}

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.