Could someone point me in the right direction as to how i would go about writing my own asort and ksort function please?

I'm still new to php...thank you!

Edit: This is what i would like to sort:

$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 />";
}

I'd want my_sort($employeeAges); to do exactly the same as asort but i have to write the function myself

Edit: This is homework...otherwise i'd simply use the functions, just need a push in the right direction, i dont expect the code. Thanks

有帮助吗?

解决方案

I don't know how your homework is specifically worded but if its that you can't use asort or ksort then you can do things like ...

function my_sort(&$my_array){
    arsort($my_array); // not using asort were using arsort
    $my_array = array_reverse($my_array,true);
}

其他提示

You'll likely need to use natsort and sort -- and you'll need to use some combination of array_keys, array_values, and array_merge

But when in doubt, Read The Manual

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top