Home > Backend Development > PHP Tutorial > Scared to think about it? About the third parameter of in_array

Scared to think about it? About the third parameter of in_array

藏色散人
Release: 2023-04-11 06:54:02
forward
2531 people have browsed it

Use in_array () Determine whether there is a certain value in the array. If the third parameter is omitted, sometimes the result may be meaningless...

For example, the following Code snippet:

<?php
$arr = [true, false];
$f = in_array(&#39;Hello&#39;, $arr);
if($f)
  echo &#39;in array&#39;;
else
  echo &#39;not found&#39;;
//结果输出 in array
Copy after login

Changed to in_array('Hello', $arr, true) This problem can be solved

This problem does not exist in JS, for example, use The indexOf () function can be rewritten like this

Scared to think about it? About the third parameter of in_array

I don’t know if this question will make you fall into silence→_→

Related recommendations: "PHP video tutorial

The above is the detailed content of Scared to think about it? About the third parameter of in_array. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
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