Sorting with sort()
<?
$dinner = array('A',
'B',
'C');
$meal = array('breakfast' => 'A',
'lunch' => 'B',
'snack' => 'C',
'dinner' => 'D');
print "Before Sorting:\n";
foreach ($dinner as $key => $value) {
print " \$dinner: $key $value\n";
}
foreach ($meal as $key => $value) {
print " \$meal: $key $value\n";
}
sort($dinner);
sort($meal);
print "After Sorting:\n";
foreach ($dinner as $key => $value) {
print " \$dinner: $key $value\n";
}
foreach ($meal as $key => $value) {
print " \$meal: $key $value\n";
}
?>
Related examples in the same category