GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Downloads
  • Documentation
  • Get Involved
  • Help
  • Getting Started
  • Introduction
  • A simple tutorial
  • Language Reference
  • Basic syntax
  • Types
  • Variables
  • Constants
  • Expressions
  • Operators

This view

  • Original page
  • New address

GeezerVison is showing www.php.net — PHP: array_reverse - Manual

PHP 8.6.0 RC5 available for testing
    array_search »
    « array_replace_recursive
    • Preface
    • Function Reference
    • Variable and Type Related Extensions
    • Arrays
    • Array Functions

    array_reverse

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

    array_reverse — Return an array with elements in reverse order

    Description

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

    Takes an input array and returns a new array with the order of the elements reversed.

    Parameters

    array

    The input array.

    preserve_keys

    If set to true numeric keys are preserved. Non-numeric keys are not affected by this setting and will always be preserved.

    Return Values

    Returns the reversed array.

    Examples

    Example #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);
    ?>

    The above example will output:

    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
    )

    See Also

    • array_flip() - Exchanges all keys with their associated values in an array

    Found A Problem?

    Learn How To Improve This Page • Submit a Pull Request • Report a Bug
    +add a note

    User Contributed Notes

    There are no user contributed notes for this page.
    • Array Functions
      • array
      • array_​all
      • array_​any
      • array_​change_​key_​case
      • array_​chunk
      • array_​column
      • array_​combine
      • array_​count_​values
      • array_​diff
      • array_​diff_​assoc
      • array_​diff_​key
      • array_​diff_​uassoc
      • array_​diff_​ukey
      • array_​fill
      • array_​fill_​keys
      • array_​filter
      • array_​find
      • array_​find_​key
      • array_​first
      • array_​flip
      • array_​intersect
      • array_​intersect_​assoc
      • array_​intersect_​key
      • array_​intersect_​uassoc
      • array_​intersect_​ukey
      • array_​is_​list
      • array_​key_​exists
      • array_​key_​first
      • array_​key_​last
      • array_​keys
      • array_​last
      • array_​map
      • array_​merge
      • array_​merge_​recursive
      • array_​multisort
      • array_​pad
      • array_​pop
      • array_​product
      • array_​push
      • array_​rand
      • array_​reduce
      • array_​replace
      • array_​replace_​recursive
      • array_​reverse
      • array_​search
      • array_​shift
      • array_​slice
      • array_​splice
      • array_​sum
      • array_​udiff
      • array_​udiff_​assoc
      • array_​udiff_​uassoc
      • array_​uintersect
      • array_​uintersect_​assoc
      • array_​uintersect_​uassoc
      • array_​unique
      • array_​unshift
      • array_​values
      • array_​walk
      • array_​walk_​recursive
      • arsort
      • asort
      • compact
      • count
      • current
      • end
      • extract
      • in_​array
      • key
      • key_​exists
      • krsort
      • ksort
      • list
      • natcasesort
      • natsort
      • next
      • pos
      • prev
      • range
      • reset
      • rsort
      • shuffle
      • sizeof
      • sort
      • uasort
      • uksort
      • usort
    • Deprecated
      • each
    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.