Vous êtes ici Fonction PHP > Description de la fonction key()

 

Recherche sur les Noms des fonctions php/mysql

 
 

key()

Définition

Retourne une clé d'un tableau associatif - (PHP 4, PHP 5)

Description

mixed key ( array &$array )

key() retourne la clé courante dans le tableau array .

Liste de paramètres

array

Le tableau.

Valeurs de retour

Retourne l'index.

Exemples

Exemple #1 Exemple avec key()

<?php
$array 
= array(
    
'fruit1' => 'apple',
    
'fruit2' => 'orange',
    
'fruit3' => 'grape',
    
'fruit4' => 'apple',
    
'fruit5' => 'apple');

// Cette boucle affiche toutes les clés
// dont la valeur vaut "apple"
while ($fruit_name current($array)) {
    if (
$fruit_name == 'apple') {
        echo 
key($array).'<br />';
    }
    
next($array);
}
?>

L'exemple ci-dessus va afficher :

fruit1<br />
fruit4<br />
fruit5<br />

Voir aussi



 
 

Bouts de code utilisant la fonction key()



<?php /* ... */   `nomvarchar(50NOT NULL,   PRIMARY KEY  (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=; /* ... */ ?>

<?php /* ... */   dernier int(11NOT NULL default '0',   PRIMARY KEY  (ip) ) TYPE=MyISAM; /* ... */ ?>

<?php /* ... */         if ($this -> options['ERROR_DISPLAY'] === true) {             echo 'ERREUR! : '$this -> errorLog[key ($this -> errorLog)],                  '<br />'; /* ... */ ?>

<?php /* ... */         if ($this -> options['ERROR_DISPLAY'] === true) {             echo 'ERREUR! : '$this -> errorLog[key ($this -> errorLog)],                  '<br />'; /* ... */ ?>

<?php /* ... */     `pseudovarchar(32NOT NULL default '',     PRIMARY key (`ip`) ) TYPE=MyISAM/* ... */ ?>