Question Detail

How to sort array ??

1 years ago Views 199 Visit Post Reply

i am try to sort array having some problms tell me the right way.


Thread Reply

Anonymous

- 1 years ago

My suggestion would be:

    function cmp($a, $b)
    {
        return strcmp($a->display_name, $b->display_name);
    }

    usort($blogusers, "cmp");

    foreach ($blogusers as $bloguser)
    {
        ...

Bili Greed

- 1 years ago

//define a comparison function
function sortArr($a, $b) {
    if ($a['status'] == $b['status']) {
        return 0;
    }
    return ($a['status'] < $b['status']) ? -1 : 1;
}

usort($array, "sortArr");

That should do what you want, you can alter the comparison function to sort on whatever key you want.

Bili Greed

- 1 years ago

$cars = array("Volvo", "BMW", "Toyota");
sort($cars);