Home > Backend Development > PHP Tutorial > php in_array syntax

php in_array syntax

高洛峰
Release: 2023-03-05 20:08:01
Original
1770 people have browsed it

bool in_array ( mixed $needle , array $haystack [, bool $strict ] ) The return value is straight or false

var_dump(in_array(0, array('s' ));

The result of this sentence is bool(true).

Because in_array will compare 0 and 's', 0 is a number type and 's' is a string type. According to the "comparison operators" in the manual It can be seen from the explanation in Chapter that when number and string are compared, the string type will be converted to number first, and then the comparison operation will be performed. The result of converting 's' to number is 0, and the result of 0 == 0 is true. Therefore, the result of in_array(0, array('s', 'ss')) is also true

If the third parameter strict of in_array is set to true, the comparison will determine whether the value and type are both Equivalent. If they are equivalent, it will return true, otherwise it will return false.

About php in_array syntax

bool in_array (mixed $needle, array $haystack [, bool $strict ] ) The return value is straight or false

$a = array('1.10', 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";  
 }
Copy after login


For more php in_array syntax related articles, please pay attention to the PHP Chinese website!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template