PHP returns an array of inverted order functions Array_reverse ()

Source: Internet
Author: User

Instance

Returns an array of flip orders:

<?php$a=array ("A" = "Volvo", "B" and "BMW", "c" = "Toyota");p Rint_r (Array_reverse ($a));? >

Definition and usage

The Array_reverse () function returns an array of flip orders.

Grammar

Array_reverse (Array,preserve)
parameters description
array required. Specifies the array.
preserve optional. Specifies whether the key name of the original array is preserved.
If set to TRUE retains the key of the number. Non-numeric keys are not affected by this setting and are always retained.
Possible values:
  • True

  • false< /p>

Technical details

return value: Returns the inverted array.
PHP version: 4 +
Update log: The preserve parameter was added in PHP 4.0.3.

More examples

Example 1

Outputs the original array, flips the array, and retains the inverted array of the original array key names:

<?php$a=array ("Volvo", "XC90", Array ("BMW", "Toyota")), $reverse =array_reverse ($a); $preserve =array_reverse ($a, true); Print_r ($a);p Rint_r ($reverse);p rint_r ($preserve);? >

Instance:

<?php$input = Array ("PHP", 4.0, Array ("Green", "Red")), $result = Array_reverse ($input); $result _keyed = Array_reverse ($input, true);? >

This will make the $result and $result _keyed have the same unit, but note the difference between the key names. The printout of the $result and the $result _keyed is shown separately:

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.