PHP/Data Structure/krsort
Reversing an Array Using krsort()
<?php
$dogs = array("A" => "AA", "Bud" => "BB","C" => "D");
ksort($dogs);
printf("<pre>%s</pre>\n", var_export($dogs, TRUE));
?>
Sorting with ksort()
<?
$meal = array("breakfast" => "A",
"lunch" => "B",
"snack" => "C",
"dinner" => "D");
print "Before Sorting:\n";
foreach ($meal as $key => $value) {
print " \$meal: $key $value\n";
}
ksort($meal);
print "After Sorting:\n";
foreach ($meal as $key => $value) {
print " \$meal: $key $value\n";
}
?>