<HTML>
<HEAD>
<TITLE>
</TITLE>
</HEAD>
<BODY>

<?php

// More about one-dimensional arrays
// Sorting arrays

$a = array('Zach' => 70, 'Mario' => 90, 'Lisa' => 95, 'Mary' => 80);
// Copy array a to array b
foreach ($a as $k => $v) {
	$b[$k] = $v;
	$c[$k] = $v;
	$d[$k] = $v;
	$e[$k] = $v;
	$f[$k] = $v;
}
//$b = $a;
//$c = $a;
//$d = $a;

echo "Before using sort: <BR>";
foreach ($a as $k => $v)
        echo "a[$k] = $v, ";

// $a=sort($a); // NO

/* Function sort sorts the array, but it resets the keys (indices) so 
that they become integers and start at 0 */

sort($a);
echo "<BR>After using sort: <BR>";
foreach ($a as $k => $v)
	echo "a[$k] = $v, ";

/* Function asort sorts the array, but it keeps the keys (indices)*/

asort($b);
echo "<BR>After using asort: <BR>";
foreach ($b as $k => $v)
        echo "b[$k] = $v, ";

/* Function ksort sorts the array with respect to the keys (indices) */

ksort($c);
echo "<BR>After using ksort: <BR>";
foreach ($c as $k => $v)
        echo "c[$k] = $v, ";

/* Function rsort is like Function sort, but it sorts in descending 
order instead of ascending order */

rsort($d);
echo "<BR>After using rsort: <BR>";
foreach ($d as $k => $v)
        echo "d[$k] = $v, ";

/* Function arsort is like Function asort, but it sorts in descending
order instead of ascending order */

arsort($e);
echo "<BR>After using arsort: <BR>";
foreach ($e as $k => $v)
        echo "e[$k] = $v, ";

/* Function krsort is like Function ksort, but it sorts in descending
order instead of ascending order */

krsort($f);
echo "<BR>After using krsort: <BR>";
foreach ($f as $k => $v)
        echo "f[$k] = $v, ";


?>

</BODY>
</HTML>
