function array_orderby() { $args = func_get_args(); $data = array_shift($args); foreach ($args as $n => $field) { if (is_string($field)) { $tmp = array(); foreach ($data as $key => $row) $tmp[$key] = $row[$field]; $args[$n] = $tmp; } } $args[] = &$data; call_user_func_array('array_multisort', $args); return array_pop($args); } $data[] = array('volume' => 67, 'edition' => 2); $data[] = array('volume' => 86, 'edition' => 1); $data[] = array('volume' => 85, 'edition' => 6); $data[] = array('volume' => 98, 'edition' => 2); $data[] = array('volume' => 86, 'edition' => 6); $data[] = array('volume' => 67, 'edition' => 7); $sorted = array_orderby($data, 'volume', SORT_DESC, 'edition', SORT_ASC);
/** * @Author MR.Sui * @title [自定义排序] * @return mixed */ public function Uorderby() { $args = func_get_args(); $data = array_shift($args); foreach ($args as $n => $field) { if (is_string($field)) { $tmp = []; array_walk($data,function($item,$key)use(&$tmp,$field){ $tmp[$key] = $item[$field]; }); $args[$n] = $tmp; } } $args[] = &$data; # sui($args); call_user_func_array('array_multisort', $args); return array_pop($args); } $menu = $this->Uorderby($menu, 'sort', SORT_DESC);