Fonction PHP array_reverse()
Exemple
Renvoie un tableau dans l'ordre inverse :
<?php
$a=array("a"=>"Volvo","b"=>"BMW","c"=>"Toyota");
print_r(array_reverse($a));
?>
Définition et utilisation
La fonction array_reverse() renvoie un tableau dans l'ordre inverse.
Syntaxe
array_reverse(array, preserve)
Valeurs des paramètres
Parameter | Description |
---|---|
array | Required. Specifies an array |
preserve | Optional. Specifies if the function should preserve the keys of the array or not. Possible values:
|
Détails techniques
Valeur de retour : | Renvoie le tableau inversé |
---|---|
Version PHP : | 4+ |
Journal des modifications PHP : | Le paramètre preserve a été ajouté en PHP 4.0.3 |
Plus d'exemples
Exemple
Renvoie le tableau d'origine, le tableau inversé et le tableau conservé :
<?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);
?>
❮ Référence de tableau PHP