Manuel PHP
key
(PHP 4, PHP 5)
key — Retourne une clé d'un tableau associatif
Description
mixed key ( array &$array )
key() retourne la clé courante dans le tableau array .
Example#1 Exemple avec key()
- <?php
- $array = array(
- 'fruit1' => 'pomme',
- 'fruit2' => 'orange',
- 'fruit3' => 'raisin',
- 'fruit4' => 'pomme',
- 'fruit5' => 'pomme');
- // Cette boucle affiche toutes les clés
- // dont la valeur vaut 'pomme'
- while ($fruit_name = current($array)) {
- if ($fruit_name == 'pomme') {
- echo key($array) . '<br />';
- }
- next($array);
- }
- ?>
Remonter 
