Php in_array syntax, phpin_array

Source: Internet
Author: User

Php in_array syntax, phpin_array

Bool in_array (mixed $ needle, array $ haystack [, bool $ strict]) returns either straight or false
 
Var_dump (in_array (0, array ('s '));

The result of this statement is bool (true ).

Because in_array compares 0 and 's', 0 is the number type, and 's' is the string type. According to the description in Chapter "comparison operators" in manual, when comparing number and string, the string type is first converted to number, and then compared. The result of converting 's' To number is 0, and the result of 0 = 0 is true, so in_array (0, array ('s', 'ss ')) the result is true.

If the third parameter strict of in_array is set to true, the system checks whether the value and type are equal during comparison. True is returned only when the values are equal. Otherwise, false is returned.

Php in_array syntax

Bool in_array (mixed $ needle, array $ haystack [, bool $ strict]) returns either straight or false

 
    1. $a = array('1.10', 12.4, 1.13);  
    2.  
    3. if (in_array('12.4', $a, true)) {  
    4.      echo "'12.4' found with strict checkn";  
    5.  }  
    6.  
    7. if (in_array(1.13, $a, true)) {  
    8.      echo "1.13 found with strict checkn";  
    9.  } 

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.