array_reverze();
Auteur: Wim - 05 september 2007 - 13:21 - Gekeurd door: marten - Hits: 4332 - Aantal punten: 1.83 (3 stemmen)
een kleine functie naar mijn wensen om een array om te draaien.
voorbeeld:
$array = array(range('a', 'z'), range(0, 9));
$array = array_reverze($array);
ob_start();
print_r($array);
$output = ob_get_contents();
ob_end_clean();
highlight_string($output);
$array = array_reverze($array);
output:
Array
(
[0] => Array
(
[0] => z
[1] => y
[2] => x
[3] => w
[4] => v
[5] => u
[6] => t
[7] => s
[8] => r
[9] => q
[10] => p
[11] => o
[12] => n
[13] => m
[14] => l
[15] => k
[16] => j
[17] => i
[18] => h
[19] => g
[20] => f
[21] => e
[22] => d
[23] => c
[24] => b
[25] => a
)
[1] => Array
(
[0] => 9
[1] => 8
[2] => 7
[3] => 6
[4] => 5
[5] => 4
[6] => 3
[7] => 2
[8] => 1
[9] => 0
)
)
( ( [0] => z [1] => y [2] => x [3] => w [4] => v [5] => u [6] => t [7] => s [8] => r [9] => q [10] => p [11] => o [12] => n [13] => m [14] => l [15] => k [16] => j [17] => i [18] => h [19] => g [20] => f [21] => e [22] => d [23] => c [24] => b [25] => a ) ( [0] => 9 [1] => 8 [2] => 7 [3] => 6 [4] => 5 [5] => 4 [6] => 3 [7] => 2 [8] => 1 [9] => 0 ) )
|
Code: |
<?php
function array_reverze ($array, $subarray=true)
{
$newArray = array();
$n = count($array);
foreach ($array as $key => $value)
{
if(is_array($value))
$value = array_reverze($value);
$newArray[--$n] = $value;
}
rsort($newArray);
return $newArray;
}
<?php function array_reverze ($array, $subarray=true) { foreach ($array as $key => $value) { $value = array_reverze($value); $newArray[--$n] = $value; } return $newArray; }
Download code (.txt)
|
|
Stemmen |
Niet ingelogd. |
|