Joseph
Joseph

Reputation: 1744

Sort multi-dimensional array BUT do not reassign top-level keys

array

$tagHolder[$row['id']] = array(


        "name" => $row['name'],
        "primary" => $row['primary'],
        "child" => $row['child'],
        "order" => $row['order']

    );

usort function

function sortAsc($x, $y){
if ( $x['order'] == $y['order'] )
 return 0;
else if ( $x['order'] < $y['order'] )
 return -1;
else
 return 1;
}

Will order by 'order' BUT will not keep the original $row['id'] keys, instead it reassigns the first prosition as 0 and so on. How can I make the sort function sort but keep the $row['key'] untouched?

Upvotes: 1

Views: 312

Answers (1)

Gumbo
Gumbo

Reputation: 655499

Use uasort instead of usort to keep the key association.

Upvotes: 3

Related Questions