How to sort array values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Fareast Adam
    New Member
    • Feb 2007
    • 51

    How to sort array values

    Anyone know how to sorting array values from least to greatest. Here the code;

    [PHP]function mulsort($a)
    {
    sort($a);
    $c = count($a);
    for($i = 0; $i < $c; $i++)
    if (is_array($a[$i]))
    mulsort($a[$i]);
    }

    $temp = array(5,4,1,3,2 );
    $test = array();

    $test = mulsort($temp);

    for($i=0; $i<sizeof($test ); $i++)
    {
    echo $test[$i].'<br>';
    }[/PHP]
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    Have you tried the sort() function?
    Seems to work on my test server (tho it messes up the index values):
    [code=php]
    <?php
    $temp = array(5,4,1,3,2 );
    sort($temp, SORT_NUMERIC);

    echo "<pre>";
    print_r($temp);
    echo "</pre>";
    ?>
    [/code]

    Outputs:
    Code:
    Array
    (
        [0] => 1
        [1] => 2
        [2] => 3
        [3] => 4
        [4] => 5
    )

    Comment

    Working...