Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

key()

Example

Return the key of the element at the current internal pointer position in the array.

<?php
$people=array(“Peter”,“Joe”,“Glenn”,“Cleveland”);
echo “The key from the current position is: “ . key($people);
?>

Definition and Usage

The key() function returns the key of the element at the current internal pointer position.

It returns FALSE on error.

Syntax

key(array)

Parameter Values

Parameter

Description

array

Required. Specifies the array to use.

Technical Details

 

Return Value:

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

PHP Version:

4+