<html><head></head><title></title>
<body>
<?
// Solution of 207 (Spring 07), Assignment 1
$a = array();
$array_size = 8;
for ($i = 1; $i <= $array_size; $i++)
{
	// Generate a random username consisting of uppercase letters
	$username_length = 5;
        $username = "";
        for ($j=0; $j < $username_length; $j++)
        {
                // Generate a random number n between 65 and 90
                // Remember uppercase letters have ASCII positions 65 to 90.
                $n = mt_rand(65,90);
                // Get the letter whose ASCII position is n
                $c =chr($n);
                // Concatenate this letter to the previous ones by
                // using the dot operator.
                $username = $username.$c;
        }
	// Generate a random 5-digot password password
	$password = mt_rand(10000,99999);
	
	// Assign the usernames to the array and the passwords as keys
	$a[$password] = $username;
}

// Print the array
echo "<b>Before Sorting: </b><br>\n";
echo "<center><table width='40%' border='1'>\n<tr><td><b>Username</b></td><td><b>Password</b></td></tr>\n";
foreach ($a as $k => $v)
	echo "<tr><td>$v</td><td>$k</td></tr>\n";
echo "</table></center>\n";

// Sort the array
asort($a);

// Print the array after sorting
echo "<b>After Sorting: </b><br>\n";
echo "<center><table width='40%' border='1'>\n<tr><td><b>Username</b></td><td><b>Password</b></td></tr>\n";
foreach ($a as $k => $v)
        echo "<tr><td>$v</td><td>$k</td></tr>\n";
echo "</table></center>\n";

?>

</body>
</html>
