Home  >  Article  >  Backend Development  >  Detailed explanation of in_array in php

Detailed explanation of in_array in php

小云云
小云云Original
2018-03-31 11:04:377875browse

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(
&#39;aaa&#39;, &#39;bbb&#39;,3
);
if( in_array(&#39;3月&#39;,$arr) ){
  echo &#39;11&#39;.PHP_EOL;
}else{
echo 22;
}
echo &#39;------------------------&#39;;  //输出11
$arr = array(
&#39;aaa&#39;, &#39;bbb&#39;,3
);
if( in_array(&#39;3月&#39;,$arr,true) ){
  echo &#39;11&#39;.PHP_EOL;
}else{
echo 22;
}
echo &#39;------------------------&#39;;//输出22
$arr = array(
&#39;aaa&#39;, &#39;bbb&#39;,&#39;3&#39;
);
if( in_array(&#39;3月&#39;,$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!

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