note 10374 deleted from function.array-reverse by salathe
| From: | salathe@php.net | Date: | Mon, 21 Sep 2020 14:51:51 +0000 |
| Subject: | note 10374 deleted from function.array-reverse by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-215359@lists.php.net to get a copy of this message | ||
Note Submitter: rahulavhad at yahoo dot com
----
This code can help in recursive reversing of the array...
<?php
$arr1 = array(2,1,array(5,2,1,array(9,8,7)),5,0);
$arr1 = array_reverse($arr1);
function Reverse_Array($array)
{ $index = 0;
foreach ($array as $subarray)
{ if (is_array($subarray))
{ $subarray = array_reverse($subarray);
$arr = Reverse_Array($subarray);
$array[$index] = $arr;
}
else {$array[$index] = $subarray;}
$index++;
}
return $array;
}
$arr2 = Reverse_Array($arr1);
?>