Re: PHP sort from .... best solution?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi

the easier way is as Mike Ford did it very elegantly with this structur:

>   function obj_date_compare($a, $b) {
>      return strcmp($a->publisertLang, $b->publisertLang);
>   }
>
>   ...
>
>   if($ingresser = array_merge($i1 ,$i2))
>   {
>      $ingresser = usort($ingresser, 'obj_date_compare');
>      listIngresser($ingresser);
>   }

the for-structure from your admin guy is also a possibility, but i think php
offers cool sort-functions like this usort-function (which was also new to
me - thx@Mike!). so it is not necessary to write your own sorting-algorithm.

.ma

A. Lyse <allyse@hardware.no> wrote@04.06.2003 13:40 Uhr:

> Hi again!
> 
> I talked to the admin guy and he said there is an easyer way to do this (as
> usual he doenst have the time to show me) so I try here:
> 
> He gave me a liddle example in c and a light translation to PHP:
> 
> Bubble sort  (exampel written in c, but can "easyly" be translated to php):
> for (i=0; i<n-1; i++) {
> for (j=0; j<n-1-i; j++)
>   if (a[j+1] < a[j]) {  /* compare the two neighbors */
>     tmp = a[j];         /* swap a[j] and a[j+1]      */
>     a[j] = a[j+1];
>     a[j+1] = tmp;
> }
> }
> 
> **************
> 
> More example of Bubble Sort:
> http://www.cs.ust.hk/faculty/tcpong/cs102/summer96/aids/bubble.html
> 
> The if-sentense must here be written to
> if($a[$j+1]->publisertLang < $a[$j]->publisertLang)
> where a is $ingresser and $n is the number of elements in $ingresser.
> 
> I
> 
> The if sentese is going in the php file pastet yesterday.
> 
> Not that yeasterdays metod did'nt work, but if somebody has an idea on this
> one and can give me a full example based on the info i've pastet yesterday
> it would be great!
> 
> Regards,
> A. Lyse
> 
> 


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux