I am still a beginner to PHP and I am currently working with arrays. I have created a web page that will print the contents of of an array in 3 different ways according to the way its sorted. However, I can not get all of the information to print. I can get each list to print seperately but it seems as though something in my script is preventing the following list to be printed once the previous prints.

In other word's, if the first list prints the second and third will not. If I comment out the first list, the second will print but the third will not. If I comment out the first and second lists, the third will print. I think that I am doing something wrong in the reset part of my code. But I have tried moving this function to before the sort function and I still get the same response. Thank you for your help. Here is what I have:

<?php
$grades = array(
"Richard"=>"95",
"Sherwood"=>"82",
"Toni"=>"98",
"Franz"=>"87",
"Melissa"=>"75",
"Roddy"=>"85"
);
echo ("Originally, the array looks like this:<br>");
for ($n; $n < count($grades); $n++) {
$line = each($grades);
echo ("$line[key]'s grade is $line[value].<br>");
}

arsort($grades);
reset($grades);
echo ("<p>After sorting the array by the value using arsort(), the array looks like this:<br>");
for ($n; $n < count($grades); $n++) {
$line = each($grades);
echo ("$line[key]'s grade is $line[value].<br>");
}

ksort($grades);
reset($grades);
echo ("<p>After sorting the array by the key using ksort(), the array looks like this:<br>");
for ($n; $n < count($grades); $n++) {
$line = each($grades);
echo ("$line[key]'s grade is $line[value].<br>");
}

?>

    Originally posted by pinchepunk
    figured it out, forgot to make $n = 0

    yah for future reference.... "MARK THREADS RESOLVED"

    and "DONT CROSS/DOUBLE POST"

      Write a Reply...