array multisort help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

array multisort help

Post 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);
Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post 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).
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Does anyone else have any input? array_multisort() still looks like the best choice. It just isn't working properly...?
Post Reply