View Full Version : array_multisort only works once.

10-17-2004, 03:46 AM
array_multisort($fill, SORT_ASC, SORT_NUMERIC);
while($x < count($fill)){
print", $fill[$x]";

The first time i do this, $fill is rearranged perfectly.
The second time i do this, it won'y rearrange.

Any ideas?
(BTW: THanks for everyones help. I've had lots of questions latly)

10-17-2004, 11:13 AM
i don't understand the question or code.

The sort is only called once (since it's outside the while-loop) so what do you mean by
The second time i do this, it won'y rearrange.

and you are using a while loop with an incrementing variable (it's kinda the convention to use $i for an incrementing variable) where you better use a for-loop. Like

for ($i=0; $i < count($fill); print', ' . $fill[$i], $i++);

or the better readable

for ($i=0; $i < count($fill); $i++){
print ', ' . $fill[$i];

10-17-2004, 12:17 PM
I advise to do all for loops with count() (or any other function) to be written like this:

for ($i=0, $n = count($fill); $i < $n; $i++)
print ', ' . $fill[$i];

The expresion in the second agument of the for loop is checked every time the loop goes thru the code so It will count fill as many times as the code is looped.