You are here: Re: Sorting arrays « PHP Programming Language « IT news, forums, messages
Re: Sorting arrays

Posted by Paul Lautman on 05/21/06 21:30

Janwillem Borleffs wrote:
> 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

Thank you for your very full and thorough explanation.

 

Navigation:

[Reply to this 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

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