有人能指出我如何编写自己的asort和ksort函数吗?
我还不熟悉php ...谢谢!
编辑:这是我想要排序的:
$employeeAges = array();
$employeeAges["Lisa"] = "28";
$employeeAges["Jack"] = "16";
$employeeAges["Ryan"] = "35";
$employeeAges["Rachel"] = "46";
$employeeAges["Grace"] = "34";
foreach( $employeeAges as $name => $age){
echo "Name: $name, Age: $age <br />";
}
我想要my_sort($ employeeAges);与asort完全相同,但我必须自己编写函数
编辑:这是作业......否则我只是简单地使用这些功能,只需要向正确的方向推进,我不期待代码。感谢
答案 0 :(得分:0)
我不知道你的作业是如何具体措辞的,但如果不能使用asort
或ksort
那么你可以做一些像......
function my_sort(&$my_array){
arsort($my_array); // not using asort were using arsort
$my_array = array_reverse($my_array,true);
}
答案 1 :(得分:-1)
您可能需要使用natsort
和sort
- 并且您需要使用array_keys
,array_values
和{{1}的某种组合}
但如果有疑问,Read The Manual