array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'pt_BR', ), 'this' => array ( 0 => 'function.array-reverse.php', 1 => 'array_reverse', ), 'up' => array ( 0 => 'ref.array.php', 1 => 'Funções para Array', ), 'prev' => array ( 0 => 'function.array-replace.php', 1 => 'array_replace', ), 'next' => array ( 0 => 'function.array-search.php', 1 => 'array_search', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'pt_BR', 'path' => 'reference/array/functions/array-reverse.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
array_reverse — Retorna um array com os elementos na ordem inversa
Recebe como entrada array
e retorna um novo array com a
ordem dos elementos invertida.
array
O array de entrada.
preserve_keys
Se definido para true
as chaves serão preservadas.
Chaves não numéricas não são afetadas por essa opção, e são sempre preservadas.
Retorna o array invertido.
Exemplo #1 array_reverse() example
<?php
$input = array("php", 4.0, array("green", "red"));
$reversed = array_reverse($input);
$preserved = array_reverse($input, true);
print_r($input);
print_r($reversed);
print_r($preserved);
?>
O exemplo acima produzirá:
Array ( [0] => php [1] => 4 [2] => Array ( [0] => green [1] => red ) ) Array ( [0] => Array ( [0] => green [1] => red ) [1] => 4 [2] => php ) Array ( [2] => Array ( [0] => green [1] => red ) [1] => 4 [0] => php )