Home  >  Article  >  Backend Development  >  How to use php key function

How to use php key function

藏色散人
藏色散人Original
2019-02-12 09:48:363533browse

PHP key() function returns the key name of the element currently pointed to by the internal pointer of the array. Its syntax is key(array). The parameter array is required and refers to the array to be used.

How to use php key function

#How to use the php key function?

php key() function syntax

Function: Returns the key name of the element currently pointed to by the internal pointer of the array.

Syntax:

key(array)

Parameters:

array Required. Specifies the array to use.

Description:

Returns the key name of the element currently pointed to by the internal pointer of the array. If an error occurs, the function returns FALSE.

php key() function usage example 1

<?php
$people = array("西门", "灭绝", "无忌");
echo "键的当前位置是:" . key($people);
?>

Output:

键的当前位置是:0

php key() function usage example 2

<?php
$arr = array("西门", "灭绝", "无忌");
$arr2 = next($arr);  //指向下一个元素 灭绝
echo key($arr);      //输出灭绝的 key值
?>

Output:

1

This article is an introduction to the PHP key function. I hope it will be helpful to friends in need!

The above is the detailed content of How to use php key function. 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