This article mainly shares with you the detailed explanation of in_array in php, mainly in the form of code, hoping to help everyone.
<?php $arr = array( 'aaa', 'bbb',3 ); if( in_array('3月',$arr) ){ echo '11'.PHP_EOL; }else{ echo 22; } echo '------------------------'; //输出11 $arr = array( 'aaa', 'bbb',3 ); if( in_array('3月',$arr,true) ){ echo '11'.PHP_EOL; }else{ echo 22; } echo '------------------------';//输出22 $arr = array( 'aaa', 'bbb','3' ); if( in_array('3月',$arr) ){ echo 11; }else{ echo 22; } //输出22 ?>
When the array elements exceed a certain number, try not to use in_array when making judgments, as it is inefficient.
Related recommendations:
How to use the implicit conversion of in_array
Compare the same values in the array in in_array in php and splice the array
Detailed explanation of implicit conversion examples of in_array in PHP
The above is the detailed content of Detailed explanation of in_array in php. For more information, please follow other related articles on the PHP Chinese website!