zoukankan      html  css  js  c++  java
  • 更改多维数组的数据结构形式

    原数组$arr1的数据结构为:

    array(1) {
      ["pic"]=>
      array(5) {
        ["name"]=>
        array(4) {
          [0]=>
          string(9) "icon1.png"
          [1]=>
          string(9) "icon2.png"
          [2]=>
          string(9) "icon3.png"
          [3]=>
          string(9) "icon4.png"
        }
        ["type"]=>
        array(4) {
          [0]=>
          string(9) "image/png"
          [1]=>
          string(9) "image/png"
          [2]=>
          string(9) "image/png"
          [3]=>
          string(9) "image/png"
        }
        ["tmp_name"]=>
        array(4) {
          [0]=>
          string(27) "C:WindowsTempphpA04F.tmp"
          [1]=>
          string(27) "C:WindowsTempphpA050.tmp"
          [2]=>
          string(27) "C:WindowsTempphpA051.tmp"
          [3]=>
          string(27) "C:WindowsTempphpA052.tmp"
        }
        ["error"]=>
        array(4) {
          [0]=>
          int(0)
          [1]=>
          int(0)
          [2]=>
          int(0)
          [3]=>
          int(0)
        }
        ["size"]=>
        array(4) {
          [0]=>
          int(1815)
          [1]=>
          int(1502)
          [2]=>
          int(3953)
          [3]=>
          int(2435)
        }
      }
    }

    要将其数据结构形式改为如下:

    array(1) {
      ["pic"]=>
      array(4) {
        [0]=>
        array(5) {
          ["name"]=>
          string(9) "icon1.png"
          ["type"]=>
          string(9) "image/png"
          ["tmp_name"]=>
          string(27) "C:WindowsTempphpA04F.tmp"
          ["error"]=>
          int(0)
          ["size"]=>
          int(1815)
        }
        [1]=>
        array(5) {
          ["name"]=>
          string(9) "icon2.png"
          ["type"]=>
          string(9) "image/png"
          ["tmp_name"]=>
          string(27) "C:WindowsTempphpA050.tmp"
          ["error"]=>
          int(0)
          ["size"]=>
          int(1502)
        }
        [2]=>
        array(5) {
          ["name"]=>
          string(9) "icon3.png"
          ["type"]=>
          string(9) "image/png"
          ["tmp_name"]=>
          string(27) "C:WindowsTempphpA051.tmp"
          ["error"]=>
          int(0)
          ["size"]=>
          int(3953)
        }
        [3]=>
        array(5) {
          ["name"]=>
          string(9) "icon4.png"
          ["type"]=>
          string(9) "image/png"
          ["tmp_name"]=>
          string(27) "C:WindowsTempphpA052.tmp"
          ["error"]=>
          int(0)
          ["size"]=>
          int(2435)
        }
      }
    }

    更改方法为:

    $arr2=array();
    foreach ($arr1['pic'] as $key01 => $val01) {
        foreach ($val01 as $key02 => $val02) {
            $arr2['pic'][$key02][$key01]=$val02;
        }
    }
    
    echo "<pre>";
    var_dump($arr2);
    echo "</pre>";
  • 相关阅读:
    MongoDb
    js暴露内部方法属性等
    JS闭包
    k8s设计模式
    scrum
    死锁
    Linux下安装php 扩展fileinfo
    linux中whereis、which、find、location的区别和用法
    Linux 命令学习记录
    windows 下 redis 的安装及使用
  • 原文地址:https://www.cnblogs.com/zhouwanqiu/p/9385715.html
Copyright © 2011-2022 走看看