Forum und email

key

(PHP 4, PHP 5)

key — Estrae la chiave corrente da un array associativo

Descrizione

mixed key ( array $array )

key() restituisce la chiave corrispondente all'attuale posizione del puntatore interno all'array.

Example#1 esempio di key()

<?php
$array 
= array(
    
'frutto1' => 'mela',
    
'frutto2' => 'arancia',
    
'frutto3' => 'uva',
    
'frutto4' => 'mela',
    
'frutto5' => 'mela');

// questo ciclo mostra tutte le chiavi
// dell'array associativo che sono uguali a 'mela'
while ($nome_frutto current($array)( {
    if (
$nome_frutto == 'mela') {
        echo 
key($array).'<br />';
    }
    
next($array);
}
?>

Vedere anche current() e next().