Reply to Re: Sorting arrays

Your name:

Reply:


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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация