How to determine whether a specified value is an array key in PHP

青灯夜游
Release: 2023-03-13 19:08:01
Original
1743 people have browsed it

In PHP, you can use the array_key_exists() function to determine whether the specified value is an array key. This function can check whether the specified key exists in an array; the syntax is "array_key_exists(key,array)" .

How to determine whether a specified value is an array key in PHP

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

In php, you can use the array_key_exists() function To determine whether the specified value is an array key.

array_key_exists() function checks whether the specified key exists in an array. If the key exists, it returns true. If the key does not exist, it returns false.

Syntax:

array_key_exists(key,array)
Copy after login
  • key Required. Specifies the key name.

  • array Required. Specifies an array.

Example: Determine whether the specified value Volvo is an array key name

<?php
header("Content-type:text/html;charset=utf-8");
$a=array("Volvo"=>"XC90","BMW"=>"X5");
if (array_key_exists("Volvo",$a))
{
    echo "指定值Volvo 是数组键名";
}
else
{
    echo "指定值Volvo 不是数组键名";
}
?>
Copy after login

Output result:

How to determine whether a specified value is an array key in PHP

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to determine whether a specified value is an array key 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template