PHP expert |
|
<?php
function sort_array($unsorted, $column, $type) {
$sorted = $unsorted;
for ($i=0; $i < sizeof($sorted)-1; $i++) {
for ($j=0; $j <sizeof($sorted)-1-$i; $j++)
if ($sorted[$j][$column] > $sorted[$j+1][$column]) {
$tmp = $sorted[$j];
$sorted[$j] = $sorted[$j+1];
$sorted[$j+1] = $tmp;
}
}
if(strtoupper($type) == 'DESC') {
$sorted = array_reverse($sorted);
}
return $sorted;
}
?>
<?php function sort_array($unsorted, $column, $type) { $sorted = $unsorted; for ($i=0; $i < sizeof($sorted)-1; $i++) { for ($j=0; $j <sizeof($sorted)-1-$i; $j++) if ($sorted[$j][$column] > $sorted[$j+1][$column]) { $tmp = $sorted[$j]; $sorted[$j] = $sorted[$j+1]; $sorted[$j+1] = $tmp; } } } return $sorted; } ?>
Ik heb ooit deze functie geschreven om arrays te sorteren.
Gebruik in jouw voorbeeld:
<?php
$sorted = sort_array($aMijnArray, 'r', 'ASC');
?>
<?php $sorted = sort_array($aMijnArray, 'r', 'ASC'); ?>
|