我有一个由两个数组合并的值数组。给定的数组按一些查询排序。现在我新的合并数组具有顺序数组值。
现在我想通过名为'featured'的键'desc'键来命令数组值,它包含数值
实施例
Array
(
[0] => stdClass Object
(
featured=> 0,
shop_update =>a,b,c )
[1] => stdClass Object
(
featured=> 1,
shop_update =>a,,c ),
[2] => stdClass Object
(
featured=> 1,
shop_update =>a,c ),
如何按特色desc命令此数组?
任何帮助?
答案 0 :(得分:0)
usort必须帮助:
<?php
function cmp($a, $b)
{
if ($a->featured == $b->featured) {
return 0;
}
return ($a->featured < $b->featured) ? 1 : -1;
}
usort($array, "cmp");