Sorting with arsort() : arsort « Data Structure « PHP






Sorting with arsort()

 
<?
$meal = array('breakfast' => 'A',
              'lunch' => 'B',
              'snack' => 'C',
              'dinner' => 'D');

print "Before Sorting:\n";
foreach ($meal as $key => $value) {
    print "   \$meal: $key $value\n";
}

arsort($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 arsort()
2.arsort( ) function reverse sorts it by its values while preserving the keys
3.arsort() function maintains the original index association and sorts the elements in reverse order.