PHP之二维数组根据某个下标排序

function arraySortByElements($array2sort,$sortField,$order,$iscount=false) {

$functionString='
    if ('.($iscount?'true':'false').'){
          if(count($a["'.$sortField.'"]) > count($b["'.$sortField.'"])) return 1*'.$order.';
        if(count($a["'.$sortField.'"]) < count($b["'.$sortField.'"])) return -1*'.$order.';
      }else{
        if($a["'.$sortField.'"] > $b["'.$sortField.'"]) return 1*'.$order.';
        if($a["'.$sortField.'"] < $b["'.$sortField.'"]) return -1*'.$order.';
      }
    return 0;';

usort($array2sort, create_function('$a,$b',$functionString));
return $array2sort;

}

猜你喜欢

转载自www.cnblogs.com/2018-05-9-ygk/p/9365952.html
今日推荐