Things to note when using the php in_array function

高洛峰
Release: 2016-11-29 14:57:19
Original
811 people have browsed it

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.


Related labels:
php
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!