Wednesday, 24 September 2014

array_reverse in PHP

array_reverse() function reverses the order of elements in the input array and returns it.

Syntax:

array_reverse(array,preserve)

Parameters Description:
array : Required. Specifies an array
preserve : Optional. Possible values:
  • true
  • false
   Specifies if the function should preserve the array's keys or not.

Example:

<?php
$daysarr1 = array( "a"=>"Sunday","b"=>"Monday","c"=>"Tuesday" );
print_r( array_reverse($daysarr1) );
?>

O/P:


Array (
          [c] => Tuesday
          [b] => Monday 
          [a] => Sunday
        )

0 comments:

Post a Comment