Learning PHP
Advanced PHP
PHP Function Reference
PHP Useful Resources
Selected Reading
© 2011 TutorialsPoint.COM
|
PHP Function key()
Syntax
Definition and Usage
The key() function returns the element key from the current internal pointer position.
Paramters
Parameter | Description |
array | Required. Specifies an array |
Return Value
This function returns FALSE on error= otherwise key.
Example
Try out following example:
<?php
$array = array(
'fruit1' => 'apple',
'fruit2' => 'orange',
'fruit3' => 'grape',
'fruit4' => 'apple',
'fruit5' => 'apple');
while ($fruit_name = current($array)) {
if ($fruit_name == 'apple') {
echo key($array).'<br />';
}
next($array);
}
?>
|
This will produce following result:
|
|
|