Reverse an array and preserve the original array in PHP

Description

The following code shows how to reverse an array and preserve the original array.

Example


/*from ww w.  ja va  2  s  .  c  o m*/
<?php
    $a=array("XML","Data",array("CSS","HTML"));
    $reverse=array_reverse($a);
    $preserve=array_reverse($a,true);

    print_r($a);
    print_r($reverse);
    print_r($preserve);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone