Jump to: navigation, search

Php key

From w3cyberlearnings

Contents

PHP function key

This function returns array key or index element of the current array position.

Syntax key

  • array: array input
key(array);

Example 1

<?php

$records = array('Alyssa' => 10, 'Emma' => 3, 'Landon' => 5);

echo key($records);
?>

Output

Alyssa

Example 2

<?php

$records = array('Alyssa' => 10, 'Emma' => 3, 'Landon' => 5);
while ($name = current($records)) {
	echo key($records);
	echo '<br/>';
	next($records);
}
?>

Output

Alyssa
Emma
Landon

Related Links


Navigation
Web
SQL
MISC
References