Php array_reverse array Reverse Order

Source: Internet
Author: User

Php array_reverse array Reverse Order

Array_reverse
(PHP 4 and PHP 5)

Array_reverse-returns an array whose content order is reversed.

Description
Array array_reverse (array $ array [, Boolean $ preserve_keys = false])
Use a command to input an array and return a new array to reverse the content.

Parameters

Array
Input array.

Preserve_keys
If this parameter is set to TRUE, the key is saved.


Return Value
Returns the reverse array.

Modify

Version description
The preserve_keys parameter of 4.0.3 is added.


Instance

Example #1 array_reverse ()

<? Php
$ Input = array ("php", 4.0, array ("green", "red "));
$ Result = array_reverse ($ input );
$ Result_keyed = array_reverse ($ input, true );
?>
This makes both $ result and $ result_keyed have the same elements, but note the difference between the keys. The printout of $ result and $ result_keyed will be:

Array
(
[0] => Array
(
[0] => green
[1] => red
)

[1] => 4
[2] => php
)
Array
(
[2] => Array
(
[0] => green
[1] => red
)

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.