Mega Code Archive

 
Categories / Php / Data Type
 

Asort() Constants

SORT_REGULAR         Compare the items normally (default).    SORT_NUMERIC         Compare the items as numeric values.    SORT_STRING          Compare the items as string values.   <HTML> <HEAD><TITLE>Sorting Arrays</TITLE></HEAD> <BODY> <CENTER> <H2>Sorting Arrays using the <code>asort()</code> function</H2> <?php     $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); ?> <TABLE> <TR>     <TD>Pet Name</TD>     <TD>Pet Owner</TD>     <TD>Pet Weight</TD>     <TD>Type of Animal</TD> </TR> <?php     foreach($petshack['weight'] as $key=>$weight) {         echo "<TR>";         echo "<TD>{$petshack['name'][$key]}</TD><TD>{$petshack['owner'][$key]} </TD>";         echo "<TD>{$weight}</TD><TD>{$petshack['animal'][$key]}</TD>";         echo "</TR>";     } ?> </TABLE> </CENTER> </BODY> </HTML>