Php in_array syntax

Source: Internet
Author: User
Tags comparison php tutorial

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 instructions in chapter "comparison operators" in the manual of the php Tutorial, number and string

During comparison, the string type is first converted to number before comparison. 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.

About phpIn_arraySyntax

<? Php
$ A = array ('1', 12.4, 1.13 );

If (in_array ('12. 4', $ a, true )){
Echo "'12. 4' found with strict checkn ";

If (in_array (1.13, $ a, true )){
Echo "1.13 found with strict checkn ";

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.