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()

  1. <?php
  2. $array = array(  
  3. 'fruit1' => 'pomme',  
  4. 'fruit2' => 'orange',  
  5. 'fruit3' => 'raisin',  
  6. 'fruit4' => 'pomme',  
  7. 'fruit5' => 'pomme');  
  8.  
  9. // Cette boucle affiche toutes les clés
  10. // dont la valeur vaut 'pomme'
  11.  
  12. while ($fruit_name = current($array)) {  
  13. if ($fruit_name == 'pomme') {  
  14. echo key($array) . '<br />';  
  15. }  
  16. next($array);  
  17. }  
  18. ?> 

Voir aussi current() et next().


Remonter Remonter
L'éditeur javascript - CSS - Gentoo - Tutoriaux PHP - Tutoriels PHP - Php - Breizh Blog