php check if a value exists in array

不言
Release: 2023-03-24 20:20:02
Original
4965 people have browsed it

The content of this article is about PHP checking whether there is a value in the array. It has certain reference value. Now I share it with you. Friends in need can refer to it

PHPin_array()The function checks whether a certain value exists in the array. If it exists, it returnsTRUE, otherwise it returnsFALSE.

Syntax:

bool in_array( mixed needle, array array [, bool strict] )
Copy after login
Copy after login

Parameter description:

Parameter Description
needle The value that needs to be searched in the array, if it is a string, it is case-sensitive
array Array to be retrieved
strict Optional, if set to TRUE, the value types in needle and array will also be checked

Example:

Copy after login
Copy after login

Character a exists in $arr_a array Strictly checked example:

Copy after login
Copy after login

Character 1 in $ Example of array as needle does not exist in arr_a array:

Copy after login
Copy after login

array$arr_bexists in$arr_aarray

PHPin_array()The function checks whether a certain value exists in the array. If it exists, it returnsTRUE, otherwise it returnsFALSE.

Syntax:

bool in_array( mixed needle, array array [, bool strict] )
Copy after login
Copy after login

Parameter description:

Parameter Description
needle The value that needs to be searched in the array, if it is a string, it is case-sensitive
array Array to be retrieved
strict Optional, if set to TRUE, the value types in needle and array will also be checked

Example:

Copy after login
Copy after login

Character a exists in the $arr_a array Strictly checked example:

Copy after login
Copy after login

Character 1 in $ Example of array as needle does not exist in arr_a array:

Copy after login
Copy after login

array$arr_bexists in$arr_aarray

Related recommendations:

PHP method to check whether the IP address is legal

PHP example code to check whether the website is down

The above is the detailed content of php check if a value exists in array. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!