php二维数组根据某个字段排序
程序员文章站
2022-03-05 08:09:35
...
/**
* 二维数组根据某个字段排序
* @author jack
*/
header('Content-Type:text/html;Charset=utf-8');
$items_arr[] = array('name' => 'f1', 'age' => "42", 'status' => 'instock');
$items_arr[] = array('name' => 'f2', 'age' => "422", 'status' => 'instock');
$items_arr[] = array('name' => 'f3', 'age' => "412", 'status' => 'instock');
$items_arr[] = array('name' => 'f4', 'age' => "432", 'status' => 'onsale');
$age_arr = array_column($items_arr, 'age');
//$sort = SORT_DESC;
$sort = SORT_ASC;
array_multisort($age_arr, $sort, $items_arr);
print_r(json_encode($items_arr));
die;
上一篇: ModelAndView
下一篇: Linux shell编程学习笔记(一)