如何使用codeigniter按字母顺序对数组进行排序
array(
Array(
[id] => 4
[business_category] => Air_conditioning-Auto
[business_name] => test business
);
Array(
[id] => 55
[business_category] => Air_conditioning-Auto
[business_name] => asdf
);
);
答案 0 :(得分:0)
从这篇文章中回答: Sort array of objects by object fields
使用usort,这是一个改编自手册的示例:
function cmp($a, $b)
{
return strcmp($a->name, $b->name);
}
usort($your_data, "cmp");
如果您要从类中对数组进行排序,并且您的排序函数cmp
也在类中定义,那么请使用:
usort($your_data, array($this, "cmp"))