|
Posted by Janwillem Borleffs on 05/21/06 17:01
Paul Lautman wrote:
> Cheers for that, do you also know why I see the oder reversal (see
> the first post)?
>
In your original compare function, the passed numeric indexes are converted
to strings (because of the var[1] syntax, which is a deprecated use of
var{1} with scalars) of which you are requesting the second character that
doesn't exist. In effect, you are comparing '' with '', which is equal.
If you look at the sequences passed, from the original array, index 1 is
compared to index 0 and index 2 is compared to index 1.
The result of the first comparison would be:
1 => array( 'OIL', 'Oil', 10 )
0 => array( 'TIR', 'Tires', 100 )
The result of the second comparison would be:
2 => array( 'SPK', 'Spark Plugs', 4 )
1 => array( 'OIL', 'Oil', 10 )
0 => array( 'TIR', 'Tires', 100 )
So, the reversal effect is the result of the first argument passed to the
compare function being considered to be equal to the second one and they are
therefore sorted in the order they where passed.
JW
Navigation:
[Reply to this message]
|