note 90793 added to function.array-multisort
| From: | mail at sport07 dot de | Date: | Sun, 10 May 2009 14:29:41 +0000 |
| Subject: | note 90793 added to function.array-multisort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-154410@lists.php.net to get a copy of this message | ||
Here is a small sniplet for sorting a 2-dimensional array in php.
function MultiSortieren($Daten,$Feld1,$Feld2)
{
$Anzahl=count($Daten);
For($y=0;$y<$Anzahl;$y++){
for($z=$y+1;$z<=$Anzahl;$z++){
if($Daten[$y][$Feld1]<$Daten[$z][$Feld1]){
$Test=$Daten[$y];
$Daten[$y]=$Daten[$z];
$Daten[$z]=$Test;
}else{
if($Daten[$y][$Feld1]==$Daten[$z][$Feld1]){
if($Daten[$y][$Feld2]>$Daten[$z][$Feld2]){
$Test=$Daten[$y];
$Daten[$y]=$Daten[$z];
$Daten[$z]=$Test;
}
}
}
}
}
return $Daten;
}
It sorts a Array ($Daten) in order of $Feld1 and then $Feld2
----------
http://www.sport07.de/code.php
----
Server IP: 69.147.83.197
Probable Submitter: 217.236.135.27
----
Manual Page -- http://www.php.net/manual/en/function.array-multisort.php
Edit -- https://master.php.net/note/edit/90793
Del: integrated -- https://master.php.net/note/delete/90793/integrated
Del: useless -- https://master.php.net/note/delete/90793/useless
Del: bad code -- https://master.php.net/note/delete/90793/bad+code
Del: spam -- https://master.php.net/note/delete/90793/spam
Del: non-english -- https://master.php.net/note/delete/90793/non-english
Del: in docs -- https://master.php.net/note/delete/90793/in+docs
Del: other reasons-- https://master.php.net/note/delete/90793
Reject -- https://master.php.net/note/reject/90793
Search -- https://master.php.net/manage/user-notes.php