Home>Article>Backend Development> How to determine whether an array value exists in php

How to determine whether an array value exists in php

青灯夜游
青灯夜游 Original
2021-12-07 18:07:34 3834browse

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)
  • 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

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!

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