How to determine whether an array value exists in php

青灯夜游
Release: 2023-03-14 10:38:01
Original
3826 people have browsed it

In PHP, you can use the in_array() function to determine whether the array value exists. The function of this function is to search whether the specified value exists in the array. The syntax is "in_array(search,array,type)"; Returns TRUE if the value exists, FALSE otherwise.

How to determine whether an array value exists in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In php, you can use in_array () function to determine whether the array value exists.

in_array() function can search whether the specified value exists in the array.

Syntax:

in_array(search,array,type)
Copy after login
  • search Required. Specifies the value to search for in the array.

  • array Required. Specifies the array to search.

  • #type Optional. If this parameter is set to true, it is checked whether the type of the searched data and the value of the array are the same.

Return value: TRUE if the value is found in the array, otherwise FALSE.

Note:

  • If the search parameter is a string and the type parameter is set to TRUE, the search is case-sensitive.

  • Returns true if the given value search exists in the array array. If the third parameter is set to true, the function returns true only if the element exists in the array and has the same data type as the given value.

  • If the parameter is not found in the array, the function returns false.

Example: Determine whether the array value "Glenn" exists

Copy after login

How to determine whether an array value exists in php

Recommended study:《PHP video tutorial

The above is the detailed content of How to determine whether an array value exists in php. 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!