Re: PHP sort from a database variable..?

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

 



sorry, needed some time to hack this one ::)

as your print_r shows that you have to sort an array which includes objects
(in this case an ingress-class - whatever this is). i tried to simulate your
environement and endet up with this:

    function array2IngressClass($array)
    {
        $inst = new ingress();
        while(list($key, $val) = each($array))
            $inst->$key = $val;
        return $inst;
    }
    
    function class2Arr($class)
    {
        return (array)$class;
    }
    
    function sortClassArray($array)
    {
        $arr = array();
        $sArr = array();
        foreach($array as $ent)
        {
            $arr[] = class2Arr($ent);
            $sArr[] = $ent->publisertLang;
        }
        
        array_multisort($arr, SORT_DESC, $sArr);
        
        $cM = count($arr);
        for($c = 0; $c < $cM; $c++)
            $arr[$c] = array2IngressClass($arr[$c]);
        
        return $arr;
    }
    
    /***********************/
    
    $i1 = hentIngresser($nettstedid,38,$sprakid,$offsetannet,$antallmotor);
    $i2 = hentIngresser($nettstedid,39,$sprakid,$offsetannet,$antallmotor);
    
    
    if($ingresser = array_merge($i1 ,$i2))
    {
        $ingresser = sortClassArray($ingresser);
        listIngresser($ingresser);
    }
    else
        echo 'Det oppstod en feil ved henting av ingresser.';
    
    /***********************/

does this work? if not which errors occour??

.ma


-- 
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