[英]PHP array_multisort not functioning correctly
I am trying to sort $ar1 by the descending order values of $ar2. 我试图按$ ar2的降序值对$ ar1进行排序。 Nothing is happening.
什么都没发生。
$ar1 = array($arperc);
$ar2 = array($arid);
array_multisort($ar1,$ar2);
print_r($ar1);
What am I missing 我错过了什么
If you want to use the elements of $ar2
as sorting keys, you need to change the order of arguments to array_multisort
: 如果要使用
$ar2
的元素作为排序键,则需要将参数的顺序更改为array_multisort
:
array_multisort($ar2, $ar1);
This will sort $ar2
in ascending order, and also change the order of $ar1
elements exactly as the order of $ar2
is changed by the sorting. 这将按升序对
$ar2
进行排序,并且还会更改$ar1
元素的顺序,因为排序会更改$ar2
的顺序。 To change the order to descending: 要将订单更改为降序:
array_multisort($ar2, SORT_DESC, $ar1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.