Sorting with ksort() : krsort « Data Structure « PHP






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";
}
?>
  
  








Related examples in the same category

1.Reversing an Array Using krsort()