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:
|
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)