/*
* Effect 排序
* author YangYunHao
* email 1126420614@qq.com
* time 2018-11-26 11:59:38
* parameter arr:排序数组,key:按什么排,type:升序降序
* */
function arraySort($arr,$key,$type='asc'){
$keyArr = []; // 初始化存放数组将要排序的字段值
foreach ($arr as $k=>$v){
$keyArr[$k] = $v[$key]; // 循环获取到将要排序的字段值
}
if($type == 'asc'){
asort($keyArr); // 排序方式,将一维数组进行相应排序
}else{
arsort($keyArr);
}
foreach ($keyArr as $k=>$v){
$newArray[$k] = $arr[$k]; // 循环将配置的值放入响应的下标下
}
$newArray = array_merge($newArray); // 重置下标
return $newArray; // 数据返回
}
$arr = json_decode('[{"status":"3","create_time":"2018-11-12 16:17:17"},{"status":"1","create_time":"2018-11-26 16:49:18"},{"status":"6","create_time":"2018-11-26 17:01:13"},{"status":8,"create_time":"2018-07-22 22:28:25"}]',true);
$newArray = arraySort($arr,'create_time','desc'); // 调用方法