Home  >  Article  >  Backend Development  >  PHP determines whether a value exists in an array

PHP determines whether a value exists in an array

(*-*)浩
(*-*)浩Original
2019-09-21 10:11:427500browse

PHP determines whether a value exists in an array

PHP in_array() function checks whether a value exists in the array and returns TRUE if it exists, otherwise it returns FALSE.

Syntax: (Recommended learning: PHP programming from entry to proficiency)

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

Parameter description:

needle, the value that needs to be searched in the array, if it is a string, it is case sensitive

array, the array that needs to be retrieved

strict, optional, if set Is TRUE, the value type in needle and array will also be checked

Example:

<?php
$arr_a = array("a", "b", "c", 1);
if(in_array("a", $arr_a)){
  echo &#39;字符 a 在 $arr_a 数组中存在&#39;;
} else {
  echo &#39;字符 a 在 $arr_a 数组中不存在&#39;;
}
?>

Character a exists in the $arr_a array Strict check Example:

<?php
$arr_a = array("a", "b", "c", 1);
if(in_array("1", $arr_a, TRUE)){
  echo &#39;字符 1 在 $arr_a 数组中存在&#39;;
} else {
  echo &#39;字符 1 在 $arr_a 数组中不存在&#39;;
}
?>

The above is the detailed content of PHP determines whether a value exists in an 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