Usage Analysis of in_array Function in php
- 2021-07-26 07:18:34
- OfStack
In this paper, the usage of in_array function in php is analyzed with examples. Share it for your reference. The details are as follows:
PHP is a weakly typed language. When using the IN_ARRAY function, take the third parameter as much as possible. 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 when 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 ture is obviously not the value we want, because PHP is mainly of weak type, so it is better for you to pay attention to 1 before.
I hope this article is helpful to everyone's php programming.