note 10374 modified in function.array-reverse by vrana

From: Date: Tue, 17 Aug 2004 14:48:57 +0000
Subject: note 10374 modified in function.array-reverse by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79897@lists.php.net to get a copy of this message
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); ?> --was-- This code can help in recursive reversing of the array... $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); http://php.net/manual/en/function.array-reverse.php

« previous php.notes (#79897) next »