• 处理三维数组,重新组合


    0x01

    三维数组中,选取其中的数据,重新组合 摘自SF上 记录下

    Code:

    -------

    function combineDika($data) {
        $result = array();
        foreach (array_shift($data) as $k=>$item) {
            $result[] = array($k=>$item);
        }
    
    
        foreach ($data as $k => $v) {
            $result2 = [];
            foreach ($result as $k1=>$item1) {
                foreach ($v as $k2=>$item2) {
                    $temp     = $item1;
                    $temp[$k2]   = $item2;
                    $result2[] = $temp;
                }
            }
            $result = $result2;
        }
        return $result;
    }
    
    $skuattr = Array
    (
        '7'  => Array
        (
            '6' => '22x33',
            '9' => '44x55',
        ),
    
        '8'  => Array
        (
            '12' => '大小号'
        ),
    
        '9'  => Array
        (
            '8'  => '金属质',
            '13' => '塑料',
        ),
    
        '16' => Array
        (
            '14' => '圆形'
        )
    
    );
    
    $a = combineDika($skuattr);
    print_r($a);

      0x02

    三维数组 转化为二维数组

    <?php
        $array = array('0'=>array('1'=>'a','2'=>'b'),
               '1'=>array('3'=>'c','4'=>'d'),
                ); foreach ($array as $key=>$value){ foreach($value as $k=>$v){ $data[] =$v; } } print_r($data); ?>

    数组转换重组数据时,可采用foreach循环外,加$i的形式,

    $array = array('0'=>array('0'=>'a','1'=>'b'),'1=>array('0'=>1));

    $data = array();

    $i=1;

    foreach($array as $k=>$v){

      $data1=$v['0'];

      //操作

      foreach($v as $key=>$value){

        $data2[$i] = $value;

        $i++;  

      }

    }  

    print_r($data2);

  • 相关阅读:
    1. Hello UWP
    ASP.NET MVC SignalR(1):背景
    ASP.NET MVC SignalR
    nekohtml转换html时标签变大写的问题
    nohup启动java命令导致dubbo无法注册
    SOA架构改造简单记录
    [转]BloomFilter——大规模数据处理利器
    IOS行货自动打包
    Kruskal算法java版
    prim算法java版
  • 原文地址:https://www.cnblogs.com/developd/p/4431199.html
Copyright © 2020-2023  润新知