Home  >  Article  >  Backend Development  >  Things to note when using the php in_array function

Things to note when using the php in_array function

高洛峰
高洛峰Original
2016-11-29 14:57:19874browse

PHP is a weakly typed language. When using the IN_ARRAY function, try to bring the third parameter. The code is as follows:

var_dump(in_array(0,array('s','sss'),true)); // return false

var_dump(in_array(0,array('s','sss'))); // return true

var_dump(in_array(0,array(1,2,3))); // return false

It can be seen from the above three functions that the first one: in_array(0,array('s','sss'),true) returns the value we want.

Use: var_dump( in_array(0,array('s','sss'))); and: var_dump(in_array(0,array(1,2,3)));

Returning true is obviously not the value we want, because the main reason PHP is a weak type, so it is better for you to pay attention to it before.


Statement:
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