Page 1 of 1

array multisort help

Posted: Thu Jun 02, 2005 11:58 pm
by hawleyjr
I have an array:

Code: Select all

Array
(
    ї0] => Array
        (
            їTS] => 1117774324
            їID] => 55
            їVALUE] => 350000
        )

    ї1] => Array
        (
            їTS] => 1117774320
            їID] => 10
            їVALUE] => 350000
        )

    ї2] => Array
        (
            їTS] => 1117774338
            їID] => 11
            їVALUE] => 450000

        )

    ї3] => Array
        (
            їTS] => 1117774314
            їID] => 19
            їVALUE] => 14000.00000
        )

    ї4] => Array
        (
            їTS] => 1117774334
            їID] => 20
            їVALUE] => 7758.33333
        )
}
and I'm trying to sort it by the array key "TS" and then by "ID"

However it is not working...?

Here is my code:

Code: Select all

foreach ($a_steps as $key => $row) {
	$a_dttm[$key]  = $row['TS'];
	$a_id[$key] = $row['ID'];
}
//sort array by time and then id
array_multisort($a_dttm, SORT_ASC,$a_id, SORT_ASC, $a_steps);

Posted: Fri Jun 03, 2005 12:48 am
by Syranide
If you want to sort by custom specifitions use the "u*" methods for that, such as "usort", which allows you to pass a custom function, however, beaware that a few if-statements and 1000 elements will make it very slow (up to a second if unlucky).

Posted: Fri Jun 03, 2005 6:57 pm
by hawleyjr
Does anyone else have any input? array_multisort() still looks like the best choice. It just isn't working properly...?