php 有没有办法选择ksort的排序?像 ASC , DESC
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20230926/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
is there a way to choose the sorting of ksort? like ASC , DESC
提问by Neta Meta
i have a use for ksort()and i need to chose sorting order(ASC/DESC).
我有一个用途ksort(),我需要选择排序顺序(ASC/DESC)。
is there a way of doing it without array_multisort()
有没有办法做到这一点 array_multisort()
回答by Matthew
krsort()for descending orderksort()for ascending order
krsort()降序ksort()升序
回答by Aryan Aly
Also :
还 :
krsort()function to sort an associative array in descending order, according to the key.
&ksortfor ascending order
plusarsort()function to sort an associative array in ascending order, according to the value.
krsort()根据key对关联数组进行降序排序的函数。
&ksort用于升序
加上arsort()函数,根据值以升序对关联数组进行排序。
回答by Renic Guatemala
natsort()mantiene la asociación clave - valor.
natsort()mantiene la asociación clave - 勇气。
$productos = array ("producto 11", "producto 1", "producto 12", "producto 2");
natsort($productos);
foreach ($productos as $key => $val) {
echo $key ." = " . $val . "<br>";
}
$productos = array ("producto 11", "producto 1", "producto 12", "producto 2");
natsort($productos);
foreach ($productos as $key => $val) {
echo $key ." = " . $val . "<br>";
}
Esto daría como respuesta:
Esto daría como respuesta:
2 = producto 1
4 = producto 2
1 = producto 11
3 = producto 12
0 = producto 20

