I did look at usort, but am still a little confused...
Here is what the $myobject object looks like:
Array
(
[0] => stdClass Object
(
[tid] => 13
[vid] => 4
)
[1] => stdClass Object
(
[tid] => 10
[vid] => 4
)
[2] => stdClass Object
(
[tid] => 34
[vid] => 4
)
[3] => stdClass Object
(
[tid] => 9
[vid] => 4
)
I saw this:
function cmp( $a, $b )
{
if( $a->weight == $b->weight ){ return 0 ; }
return ($a->weight < $b->weight) ? -1 : 1;
}
usort($myobject,'cmp');
I'm trying to sort according to tid, but, I guess I'm just not sure really if I have to change weight to something? Or will it just work as is? I tried it, but nothing outputted...
cmp is the a callback function that usort uses to compare complex objects (like yours) to figure out how to sort them. modify cmp for your use (or rename it to whatever you wish)
function cmp( $a, $b )
{
if( $a->tid == $b->tid ){ return 0 ; }
return ($a->tid < $b->tid) ? -1 : 1;
}
usort($myobject,'cmp');
function sort_by_tid( $a, $b )
{
if( $a->tid == $b->tid ){ return 0 ; }
return ($a->tid < $b->tid) ? -1 : 1;
}
usort($myobject,'sort_by_tid');