按照数组键名按名称排序
按照数组键名按名称排序
这个问题已经有答案了:
我有一个数组,像这样,我怎样才能按照“姓名”排序呢?
Array ( [0] => Array ( [id] => 1 [name] => status_category_confide ) [1] => Array ( [id] => 2 [name] => status_category_love ) [2] => Array ( [id] => 3 [name] => status_category_household ) [3] => Array ( [id] => 4 [name] => status_category_family ) [4] => Array ( [id] => 5 [name] => status_category_friends ) [5] => Array ( [id] => 6 [name] => status_category_colleague ) [6] => Array ( [id] => 7 [name] => status_category_work ) [7] => Array ( [id] => 8 [name] => status_category_ambition ) )
我尝试使用“sort”函数,但它没有起作用
$get_status_mood=mysqli_query($con, "select id, name from category"); while ($gsm=mysqli_fetch_array($get_status_mood)) { //array_push($status_category, constant($gsm['name'])); $status_category[] = array( "id"=>$gsm['id'], "name"=>$gsm['name'] ); } sort($status_category); for ($i=0; $i<count($status_category); $i++) { echo"".$status_category[$i]['name'].""; }
我想按照姓名的顺序显示结果
admin 更改状态以发布 2023年5月21日