PHP array_reverse() Funzione
Esempio
Restituisce un array nell'ordine inverso:
<?php
$a=array("a"=>"Volvo","b"=>"BMW","c"=>"Toyota");
print_r(array_reverse($a));
?>
Definizione e utilizzo
La funzione array_reverse() restituisce un array nell'ordine inverso.
Sintassi
array_reverse(array, preserve)
Valori dei parametri
Parameter | Description |
---|---|
array | Required. Specifies an array |
preserve | Optional. Specifies if the function should preserve the keys of the array or not. Possible values:
|
Dettagli tecnici
Valore di ritorno: | Restituisce la matrice invertita |
---|---|
Versione PHP: | 4+ |
Registro delle modifiche PHP: | Il parametro preservare è stato aggiunto in PHP 4.0.3 |
Altri esempi
Esempio
Restituisce l'array originale, l'array invertito e l'array conservato:
<?php
$a=array("Volvo","XC90",array("BMW","Toyota"));
$reverse=array_reverse($a);
$preserve=array_reverse($a,true);
print_r($a);
print_r($reverse);
print_r($preserve);
?>
❮ Riferimento all'array PHP