zoukankan      html  css  js  c++  java
  • php 二维数组索引乱序 shuffle() 函数;

    在实际开发中有一个打乱数组排序的案例  

    案例代码如下

     public function index(){
            if(IS_POST){
                #获取卖单列表
                $buy_list=M('buy')->where(['status'=>1])->field('num')->select();
                #获取卖单列表
                $sell_list=M('sell')->where(['status'=>1])->field('num')->select();
                foreach($buy_list as $key=>$value){
                    $buy_list[$key]['type']='buy';
                    $buy_list[$key]['rmb']=round($value['num']*6.3,2);
                }
    
                foreach($sell_list as $k=>$v){
                    $sell_list[$k]['type']='sell';
                    $sell_list[$k]['rmb']=round($v['num']*6.3,2);
                }
    
                $order=(array_merge($buy_list,$sell_list));
                shuffle($order);
                if($order){
                    $this->ajaxReturn(['code'=>200,'data'=>$order]);
                }
                $this->ajaxReturn(['code'=>100,'msg'=>'暂时没有订单数据,您可以预下下单,系统会优先匹配']);
            }else{
                $this->display();
            }

    在合并数组后只需要使用shuffle()函数对数据排序进行乱序处理即可

  • 相关阅读:
    常用的标签分类
    css 实现动态二级菜单
    5大主流浏览器内核
    MySQL里面的子查询
    Algolia Search
    Nginx配置
    PHP中Abstract与Interface区别
    Shell 基本语法
    百度 echarts K线图使用
    php_soap扩展应用
  • 原文地址:https://www.cnblogs.com/LiChen-789/p/10124029.html
Copyright © 2011-2022 走看看