Home  >  Article  >  Backend Development  >  php in_array function checks whether a certain value exists in the array

php in_array function checks whether a certain value exists in the array

怪我咯
怪我咯Original
2017-07-16 14:51:331667browse

This article mainly introduces the use of PHP in_arrayfunctionchecks whether a certain value exists in the array, and analyzes the function of the in_array function in more detail. Definitions and related usage skills and Notes have certain reference value. Friends in need can refer to it

The example in this article describes how PHP uses the in_array function to check whether a certain value exists in the array. Methods. Share it with everyone for your reference. The specific analysis is as follows:

PHP uses the in_array() function to check whether a certain value exists in the array. If it exists, it returns TRUE, otherwise it returns FALSE. It is very easy to use. Let me introduce in_array() in depth. ) Function.

Recently when writing a piece of code in PHP, I need to use it to determine whether a certain value is in another set of values. The in_array function is used to check whether a certain value exists in the array. It is rather vague to understand directly through concepts, and its function can be understood through specific examples.

The syntax is as follows:

bool in_array( mixed needle, array array [, bool strict] )

Parameter description:

Parameter Explanation
needle Need to search the value of in the array, if it is a string, differentiate Case
array Array to be retrieved
strict Optional, if set to TRUE, the value types in needle and array will also be checked

Example

<?php
$people = array("Bill", "Steve", "Mark", "David");

if (in_array("23", $people, TRUE))
  {
  echo "匹配已找到<br>";
  }
else
  {
  echo "匹配未找到<br>";
  }
if (in_array("Mark",$people, TRUE))
  {
  echo "匹配已找到<br>";
  }
else
  {
  echo "匹配未找到<br>";
  }

if (in_array(23,$people, TRUE))
  {
  echo "匹配已找到<br>";
  }
else
  {
  echo "匹配未找到<br>";
  }
?>

The above is the detailed content of php in_array function checks whether a certain value exists in the array. 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