Detailed explanation of in_array in php

小云云
Release: 2023-03-22 20:52:02
Original
7890 people have browsed it

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
?>
Copy after login

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!

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template