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

PHP determines whether a value exists in an array

(*-*)浩
Release: 2023-02-24 15:16:01
Original
7540 people have browsed it

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] )
Copy after login

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

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

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!

Related labels:
php
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