我一直在使用 array_multisort 函数,但我正在努力让它与我拥有的数组一起工作。
这是我要排序的多维数组的 var 转储:
array(2) {
[1]=> array(6) {
["totalprice"]=> float(103.32)
["itemsprice"]=> float(83.33)
["deliveryprice"]=> float(19.99)
["qualityscore"]=> int(100)
["reliabilityscore"]=> int(100)
["itemtemplates"]=> array(4) {
[1]=> array(3) {
["price"]=> float(374)
["qty"]=> int(200)
["name"]=> string(17) "English A2 Poster"
}
[3]=> array(3) {
["price"]=> float(374)
["qty"]=> int(500)
["name"]=> NULL
}
[6]=> array(3) {
["price"]=> float(83.333333333333)
["qty"]=> int(100)
["name"]=> string(16) "French A3 Poster"
}
[5]=> array(3) {
["price"]=> float(83.333333333333)
["qty"]=> int(5000) ["name"]=> NULL
}
}
}
[2]=> array(6) {
["totalprice"]=> float(103.32)
["itemsprice"]=> float(83.33)
["deliveryprice"]=> float(19.99)
["qualityscore"]=> int(80)
["reliabilityscore"]=> int(100)
["itemtemplates"]=> array(4) {
[1]=> array(3) {
["price"]=> float(374)
["qty"]=> int(200)
["name"]=> string(17) "English A2 Poster"
}
[3]=> array(3) {
["price"]=> float(374)
["qty"]=> int(500)
["name"]=> NULL
}
[6]=> array(3) {
["price"]=> float(83.333333333333)
["qty"]=> int(100)
["name"]=> string(16) "French A3 Poster"
}
[5]=> array(3) {
["price"]=> float(83.333333333333)
["qty"]=> int(5000) ["name"]=> NULL
}
}
}
[3]=> array(6) {
["totalprice"]=> float(83.32)
["itemsprice"]=> float(63.33)
["deliveryprice"]=> float(19.99)
["qualityscore"]=> int(60)
["reliabilityscore"]=> int(40)
["itemtemplates"]=> array(4) {
[1]=> array(3) {
["price"]=> float(374)
["qty"]=> int(200)
["name"]=> string(17) "English A2 Poster"
}
[3]=> array(3) {
["price"]=> float(374)
["qty"]=> int(500)
["name"]=> NULL
}
[6]=> array(3) {
["price"]=> float(83.333333333333)
["qty"]=> int(100)
["name"]=> string(16) "French A3 Poster"
}
[5]=> array(3) {
["price"]=> float(83.333333333333)
["qty"]=> int(5000) ["name"]=> NULL
}
}
}
}
我需要按总价格 ASC 排序,然后按质量得分 DESC 排序。
我尝试了以下方法:
$sorted = array_multisort($array['totalprice'], SORT_ASC, SORT_NUMERIC,
$array['qualityscore'], SORT_NUMERIC, SORT_DESC);
不幸的是,这不起作用。有没有人更精通这个功能并且可能知道我哪里出错了?或者如果有一个简单的替代这个功能?
提前致谢!