zoukankan      html  css  js  c++  java
  • php数组操作,内容相同,键值不同,互换

    $title = array("A"=>"创建时间","C"=>"商品信息","D"=>"商品ID","F"=>"所属店铺","G"=>"商品数","I"=>"订单状态","J"=>"订单类型","M"=>"付款金额","S"=>"效果预估","Y"=>"订单编号","AD"=>"广告位名称");
    
    
    $fild = array('creatTime'=>'创建时间','orderNumber'=>'订单编号','goodsTitle'=>'商品信息','shopName'=>'所属店铺','goodsNums'=>'商品数','paymentAmount'=>'付款金额','orderStatus'=>'订单状态','orderType'=>'订单类型','groupName'=>'广告位名称','commissionAmount'=>'佣金金额','goodsId'=>'商品ID');//数据库中对应的字段
    
            foreach ($title as $k=>$v)
            {
                if($key = array_search($v,$fild)){//要获取excel的列值
                    $dataFild ["$key"]=$v;
                }
            }
    
            var_dump($dataFild);
    
    //结果
    array(10) {
      ["creatTime"]=>
      string(1) "A"
      ["goodsTitle"]=>
      string(1) "C"
      ["goodsId"]=>
      string(1) "D"
      ["shopName"]=>
      string(1) "F"
      ["goodsNums"]=>
      string(1) "G"
      ["orderStatus"]=>
      string(1) "I"
      ["orderType"]=>
      string(1) "J"
      ["paymentAmount"]=>
      string(1) "M"
      ["orderNumber"]=>
      string(1) "Y"
      ["groupName"]=>
      string(2) "AD"
    }
     
    //其实可以通过php内置函数来做,(下面两个函数搭配估计差不多)
    //•array_combine — 创建一个数组,用一个数组的值作为其键名,另一个数组的值作为其值
    //•array_flip — 交换数组中的键和值



  • 相关阅读:
    halcon 2极坐标转笛卡尔坐标
    xmal随笔
    halcon 3焊点查找
    halcon 药丸查找
    halcon 1区域保存生成
    mokee源码下载
    多个DataTable的合并成一个新表
    代码分析工具
    SQL大量数据查询分页存储过程
    sqlite3使用简介
  • 原文地址:https://www.cnblogs.com/fps2tao/p/8784351.html
Copyright © 2011-2022 走看看