我的数组如下所示:
Array
(
[0] => Array
(
[id] => 613
[kleur] => royalblauw/wit
[maat] => maat XL
[voorraad] => 100
[sort] => 0
[prijs] => 4.1320
)
[1] => Array
(
[id] => 614
[kleur] => royalblauw/wit
[maat] => maat XXL
[voorraad] => 100
[sort] => 1
[prijs] => 4.1320
)
[2] => Array
(
[id] => 620
[kleur] => zwart/wit
[maat] => maat XL
[voorraad] => 100
[sort] => 2
[prijs] => 4.1320
)
etc.etc.
我想要的是按“maat”(大小)对数组进行排序。如您所见,有多个条目具有相同的“maat”。
我已经尝试了几个小时,但仍然不是一个好结果。当然,我也一直在研究 Stackoverflow。这是我到现在为止的。
职能:
function cmp($a, $b)
{
$sizes = array(
"116" => 0,
"128" => 1,
"140" => 2,
"152" => 3,
"164" => 4,
"XXS" => 5,
"XS" => 6,
"S" => 7,
"M" => 8,
"L" => 9,
"XL" => 10,
"XXL" => 11,
"XXXL" => 12,
"XXXXL" => 13,
"XXXXXL" => 14
);
$asize = $sizes[$a];
$bsize = $sizes[$b];
if ($asize == $bsize) {
return 0;
}
return ($asize > $bsize) ? 1 : -1;
}
function aasort (&$array, $key) {
$sorter=array();
$ret=array();
reset($array);
foreach ($array as $ii => $va) {
$sorter[$ii]=$va[$key];
}
uasort($sorter, "cmp");
foreach ($sorter as $ii => $va) {
$ret[$ii]=$array[$ii];
}
$array=$ret;
}
并调用函数 aasort:
aasort($maatkleur_array,"maat");
请你帮帮我。我希望很清楚我想要达到的目标。