SORT_REGULAR Compare the items normally (default).
SORT_NUMERIC Compare the items as numeric values.
SORT_STRING Compare the items as string values.
Sorting Arrays
Sorting Arrays using the asort()
function
$petshack['name'] = array('A', 'B', 'C', 'D', 'E');
$petshack['owner'] = array('J', 'A', 'C', 'A', 'H');
$petshack['weight'] = array(20, 10, 3, 54, 30);
$petshack['animal'] = array('Dog', 'Cat', 'Cat', 'Dog', 'Dog');
asort($petshack['weight'], SORT_NUMERIC);
?>
Pet Name
Pet Owner
Pet Weight
Type of Animal
foreach($petshack['weight'] as $key=>$weight) {
echo "";
echo "{$petshack['name'][$key]} {$petshack['owner'][$key]} ";
echo "{$weight} {$petshack['animal'][$key]} ";
echo " ";
}
?>