Home  >  Article  >  Backend Development  >  PHP array introductory tutorial array_key_exists() function

PHP array introductory tutorial array_key_exists() function

WBOY
WBOYOriginal
2016-07-25 08:58:00880browse
This article introduces the usage of the array_key_exists() function of the PHP array function. Friends in need can refer to it.

In the php array function, the function array_key_exists() implements this function: Returns true if a specified key is found in an array, false otherwise.

The form is as follows: boolean array_key_exists(mixed key,array array);

Example, search for apple in the array key, if found, the color of this fruit will be output:

<?php
//array_key_exists函数用法举例
//by bbs.it-home.org
$fruit["apple"] = "red";  
$fruit["banana"] = "yellow";  
$fruit["pear"] = "green";  
if(array_key_exists("apple", $fruit)){  
printf("apple's color is %s",$fruit["apple"]);  
}  
  
//apple's color is red
?>


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