开发者

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?


Use uasort instead of usort to keep the key association.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜