tut mir wirklich leid aber ich bekomme es trotz 150 onlinehilfen nicht gebacken :/
ich habe ein dieses array:
product[1][0] = 15;
product[1][1] = 52;
product[2][0] = 6;
product[2][1] = 15;
product[3][0] = 4;
product[3][1] = 15;
product[4][0] = 8;
product[4][1] = 45;
product[5][0] = 43;
product[5][1] = 5;
....
es soll sortiert werden daß es am ende so ausschaut (also nach der ersten stelle sortiert):
product[1][0] = 4;
product[1][1] = 15;
product[2][0] = 6;
product[2][1] = 15;
product[3][0] = 8;
product[3][1] = 45;
product[4][0] = 15;
product[4][1] = 52;
product[5][0] = 43;
product[5][1] = 5;
habe schon eine funktion gefunden die angeblich genau das machen soll:
leider tut sie bei mir irgendwie gar nix ... wäre cool wenn mir jemand hilft *dummis*PHP-Code:
function incision_sort($arr, $col){
for($k = 0; $k < sizeof($arr)-1; $k++){
// $arr[$k+1] is possibly in the wrong place. Take it out.
$t = $arr[$k+1];
$i = $k;
// Push $arr[i] to the right until we find the right place for $t.
while($i >= 0 && $arr[$i][$col] > $t[$col]){
$arr[$i+1] = $arr[$i];
$i--;
}
// Insert $t into the right place.
$arr[$i+1] = $t;
}// End sort
echo"lol";
return $arr;
}
incision_sort($product, 1);
Lesezeichen