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

藏色散人
藏色散人forward
2022-07-15 13:52:352530browse

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

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!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete