Re: PHP sort from a database variable..?

From: Date: Tue, 03 Jun 2003 22:35:17 +0000
Subject: Re: PHP sort from a database variable..?
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-28268@lists.php.net to get a copy of this message
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

« previous php.db (#28268) next »