[UPHPU] easy asort() question

Mac Newbold mac at macnewbold.com
Wed Jun 22 07:51:45 MDT 2005


Yesterday at 3:58pm, John M said:

> Here is the code I've typed in...

If you can show us a little more output, that would be helpful. For 
example, try adding these:

print_r($math);
> while (list($index,$value) = each($math))
> {
>  $gradestudent[] = $math[$index].$student[$index];
> }
print_r($gradestudent);
> asort($gradestudent);
print_r($gradestudent); # this is basically what you showed us below

One problem with what you're expecting to happen is here:
>  $gradestudent[] = $math[$index].$student[$index];
If you want to sort gradestudent by value, maintaining the key 
associations, you'd want to have some sort of meaningful key for each 
value. The way this is writen now, they're just getting numeric keys 
automatically assigned as you add values to the list.

In case it's useful, another common way of writing that loop is like so:
foreach ($math as $index => $value) { ... }

Thanks,
Mac

--
Mac Newbold		MNE - Mac Newbold Enterprises, LLC
mac at macnewbold.com	http://www.macnewbold.com/



More information about the UPHPU mailing list