Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP中的进程数组_Php_Arrays - Fatal编程技术网

PHP中的进程数组

PHP中的进程数组,php,arrays,Php,Arrays,我有一个数组: array(2) { [0]=> array(1) { [57]=> array(5) { ["name"]=> string(8) "sky.docx" ["type"]=> string(71) "application/vnd.openxmlformats-officedocument.wordprocessingml.document"

我有一个数组:

array(2) { 
    [0]=> array(1) { 
        [57]=> array(5) { 
             ["name"]=> string(8) "sky.docx" 
             ["type"]=> string(71) "application/vnd.openxmlformats-officedocument.wordprocessingml.document" 
             ["size"]=> int(14413) 
             ["tmp_name"]=> string(24) "D:\xampp\tmp\php381B.tmp"            
             ["error"]=> int(0) 
             } 
        } 
    [1]=> array(1) { 
         [57]=> array(5) {            
             ["name"]=> string(50) "11536101_730381813774270_2393648058450493003_n.jpg" 
             ["type"]=> string(10) "image/jpeg" 
             ["size"]=> int(52314) 
             ["tmp_name"]=> string(24) "D:\xampp\tmp\php78F5.tmp"           
             ["error"]=> int(0) 
          } 
      } 
}
我想更改格式:

array(2) {
         [57]=> array(5) {
               ["name"]=> string(50) "11401351_729347963877655_7852714736534111540_n.jpg" 
               ["type"]=> string(10) "image/jpeg" 
               ["size"]=> int(45023) 
               ["tmp_name"]=> string(24) "D:\xampp\tmp\php4FDA.tmp"  
               ["error"]=> int(0) 
             } 
          [59]=> array(5) { 
               ["name"]=> string(49) "11427212_729926670486451_281410776821596523_n.jpg" 
               ["type"]=> string(10) "image/jpeg" 
               ["size"]=> int(29765) 
               ["tmp_name"]=> string(24) "D:\xampp\tmp\php4FEB.tmp" 
               ["error"]=> int(0) 
           } 
}

请帮帮我

试试这样的东西

$newArray = [];
foreach ($oldArray as $key => $value) {
    $arrayKey = key($value);
    $newArray[$arrayKey] = $value[$arrayKey];
}

可能意味着将三维数组变成二维数组,并且关键字不能重复

      //just change format
        $begin = [
                [   
                    57 =>[    
                    "name"=> "sky.docx" ,
                    "type"=>  "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ,
                    "size"=> 14413,
                    "tmp_name"=> "D:\xampp\tmp\php381B.tmp", 
                    "error"=> 0,
                    ],  
                ],
                [   
                    57 =>[    
                    "name"=> "sky.docx", 
                    "type"=>  "application/vnd.openxmlformats-officedocument.wordprocessingml.document", 
                    "size"=> 14413,
                    "tmp_name"=> "D:\xampp\tmp\php381B.tmp", 
                    "error"=> 0,
                    ]  
                ]
        ];
        print_r($begin);
        $result = [];
        foreach ($begin as $key => $value) {
            foreach ($value as $k=>$v) {
                if(array_key_exists($k, $result)){
                    $result[$k+2] = $v;
                }else{
                    $result[$k] = $v;
                }
            }
        }
        print_r($result);

$begin

我测试了这个,它工作正常

$length = count($myOldArray);

for($i = 0; $i< $length; $i++)
$myNewArray[57+$i] = $myOldArray[$i][57];
$length=count($myOldArray);
对于($i=0;$i<$length;$i++)
$myNewArray[57+$i]=$myOldArray[$i][57];
您可以使用函数

函数只是用来知道数组是否有任何元素,因为57之后需要索引59,假设是增量2。您也可以使用或任何其他功能

$result = array();

array_walk($array, function($row) use (&$result){
      $key=key($row);
      $result[(count($result)? $key+2 : $key)]=$row[$key];
});

print_r($result);
测试结果

[akshay@localhost tmp]$ cat test.php
<?php

$array = array (
  0 => 
  array (
    57 => 
    array (
      'name' => 'sky.docx',
      'type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
      'size' => 14413,
      'tmp_name' => 'D:
mpp mp\\php381B.tmp',
      'error' => 0,
    ),
  ),
  1 => 
  array (
    57 => 
    array (
      'name' => 'sky.docx',
      'type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
      'size' => 14413,
      'tmp_name' => 'D:
mpp mp\\php381B.tmp',
      'error' => 0,
    ),
  ),
);

print_r($array);

$result = array();
array_walk($array, function($row) use (&$result){

  // Get index
  $key=key($row);

  // array_key_exists is used since you need index 59 after 57
  // assumption is increment 2
  $result[(count($result)? $key+2 : $key)]=$row[$key];
});

print_r($result);
?>
[akshay@localhost tmp]$ php test.php
Array
(
    [0] => Array
        (
            [57] => Array
                (
                    [name] => sky.docx
                    [type] => application/vnd.openxmlformats-officedocument.wordprocessingml.document
                    [size] => 14413
                    [tmp_name] => D:
mpp mp\php381B.tmp
                    [error] => 0
                )

        )

    [1] => Array
        (
            [57] => Array
                (
                    [name] => sky.docx
                    [type] => application/vnd.openxmlformats-officedocument.wordprocessingml.document
                    [size] => 14413
                    [tmp_name] => D:
mpp mp\php381B.tmp
                    [error] => 0
                )

        )

)
Array
(
    [57] => Array
        (
            [name] => sky.docx
            [type] => application/vnd.openxmlformats-officedocument.wordprocessingml.document
            [size] => 14413
            [tmp_name] => D:
mpp mp\php381B.tmp
            [error] => 0
        )

    [59] => Array
        (
            [name] => sky.docx
            [type] => application/vnd.openxmlformats-officedocument.wordprocessingml.document
            [size] => 14413
            [tmp_name] => D:
mpp mp\php381B.tmp
            [error] => 0
        )

)

到目前为止,您尝试了什么来更改此格式?