phpday 2027 - Call for Papers

array_reverse

(PHP 4, PHP 5, PHP 7, PHP 8)

array_reverse — Restituisce un array con gli elementi in ordine inverso

Descrizione

function array_reverse(array $array, bool $preserve_keys = false): array

Prende un array in input e restituisce un nuovo array con l'ordine degli elementi invertito.

Elenco dei parametri

array

L'array in input.

preserve_keys

Se impostato a true, le chiavi numeriche vengono preservate. Le chiavi non numeriche non sono influenzate da questa impostazione e vengono sempre preservate.

Valori restituiti

Restituisce l'array invertito.

Esempi

Example #1 Esempio di array_reverse()

<?php
$input  = array("php", 4.0, array("verde", "rosso"));
$reversed = array_reverse($input);
$preserved = array_reverse($input, true);

print_r($input);
print_r($reversed);
print_r($preserved);
?>

Il precedente esempio visualizzerà:

Array
(
    [0] => php
    [1] => 4
    [2] => Array
        (
            [0] => verde
            [1] => rosso
        )

)
Array
(
    [0] => Array
        (
            [0] => verde
            [1] => rosso
        )

    [1] => 4
    [2] => php
)
Array
(
    [2] => Array
        (
            [0] => verde
            [1] => rosso
        )

    [1] => 4
    [0] => php
)

Vedere anche:

  • array_flip() - Scambia tutte le chiavi di un array con i valori ad esse associati

+add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top