Javascript 从AJAX提交中拆分数组$\u文件

Javascript 从AJAX提交中拆分数组$\u文件,javascript,php,jquery,arrays,ajax,Javascript,Php,Jquery,Arrays,Ajax,我的html表单中有一个公共输入和两个文件输入,如下所示: div class="col-md-4"> <div class="form-group"> <label class="control-label col-md-3">Size</label> <div class="col-md-9"> <?php $size = arra

我的html表单中有一个公共输入和两个文件输入,如下所示:

div class="col-md-4">
   <div class="form-group">
       <label class="control-label col-md-3">Size</label>
           <div class="col-md-9">
              <?php
                $size = array(
                         "type" => "text",
                         "name" => "size",
                         "id" => "size",
                         "class" => "form-control"
                        );
               echo form_input($size);
               ?>
               <span class="help-block"></span>
            </div>
          </div>
       </div>


<div class="col-md-6">
    <div class="form-group">
        <label class="control-label col-md-2">Image Container:</label>
            <div class="col-md-10">
               <input type="file" multiple="" name="images_container[]" id="file_container" required="required">
               <p class="help-block"></p>
            </div>
    </div>
</div>

 <div class="col-md-6">
     <div class="form-group">
        <label class="control-label col-md-2">Image If Coil Is Damage</label>
             <div class="col-md-10">
                <input type="file" multiple="" name="images[]" id="files" >
                <p class="help-block"></p>
             </div>
     </div>
</div>
Array
(
[file_container_0] => Array
    (
        [name] => bonus.jpg
        [type] => image/jpeg
        [tmp_name] => D:\xampp\tmp\php95B4.tmp
        [error] => 0
        [size] => 616252
    )

[file_container_1] => Array
    (
        [name] => coolas.jpg
        [type] => image/jpeg
        [tmp_name] => D:\xampp\tmp\php9613.tmp
        [error] => 0
        [size] => 641576
    )

[file_container_2] => Array
    (
        [name] => preview.jpg
        [type] => image/jpeg
        [tmp_name] => D:\xampp\tmp\php9633.tmp
        [error] => 0
        [size] => 474285
    )

[file_coil0] => Array
    (
        [name] => 1280x800.jpg
        [type] => image/jpeg
        [tmp_name] => D:\xampp\tmp\php9653.tmp
        [error] => 0
        [size] => 214172
    )

[file_coil1] => Array
    (
        [name] => 1280x960.jpg
        [type] => image/jpeg
        [tmp_name] => D:\xampp\tmp\php9674.tmp
        [error] => 0
        [size] => 261002
    )

)
我的问题是,如何将此数组拆分为两个数组

第一个数组

Array
(
[file_container_0] => Array
    (
        [name] => bonus.jpg
        [type] => image/jpeg
        [tmp_name] => D:\xampp\tmp\php95B4.tmp
        [error] => 0
        [size] => 616252
    )

[file_container_1] => Array
    (
        [name] => coolas.jpg
        [type] => image/jpeg
        [tmp_name] => D:\xampp\tmp\php9613.tmp
        [error] => 0
        [size] => 641576
    )

[file_container_2] => Array
    (
        [name] => preview.jpg
        [type] => image/jpeg
        [tmp_name] => D:\xampp\tmp\php9633.tmp
        [error] => 0
        [size] => 474285
    )

)
Array
(
    [file_coil0] => Array
    (
        [name] => 1280x800.jpg
        [type] => image/jpeg
        [tmp_name] => D:\xampp\tmp\php9653.tmp
        [error] => 0
        [size] => 214172
    )

[file_coil1] => Array
    (
        [name] => 1280x960.jpg
        [type] => image/jpeg
        [tmp_name] => D:\xampp\tmp\php9674.tmp
        [error] => 0
        [size] => 261002
    )

)
第二个数组

Array
(
[file_container_0] => Array
    (
        [name] => bonus.jpg
        [type] => image/jpeg
        [tmp_name] => D:\xampp\tmp\php95B4.tmp
        [error] => 0
        [size] => 616252
    )

[file_container_1] => Array
    (
        [name] => coolas.jpg
        [type] => image/jpeg
        [tmp_name] => D:\xampp\tmp\php9613.tmp
        [error] => 0
        [size] => 641576
    )

[file_container_2] => Array
    (
        [name] => preview.jpg
        [type] => image/jpeg
        [tmp_name] => D:\xampp\tmp\php9633.tmp
        [error] => 0
        [size] => 474285
    )

)
Array
(
    [file_coil0] => Array
    (
        [name] => 1280x800.jpg
        [type] => image/jpeg
        [tmp_name] => D:\xampp\tmp\php9653.tmp
        [error] => 0
        [size] => 214172
    )

[file_coil1] => Array
    (
        [name] => 1280x960.jpg
        [type] => image/jpeg
        [tmp_name] => D:\xampp\tmp\php9674.tmp
        [error] => 0
        [size] => 261002
    )

)

通过检查索引位置的子串,我们可以对两个阵列进行衍射:

$file_container_array = array();
$file_coil_array = array();

$files_array = $_FILES;
foreach($files_array as $key => $file)
if (strpos($key, 'file_container') !== false) {
    $file_container_array[] = $file;
} else if(strpos($key, 'file_coil') !== false) { 
    $file_coil_array[] = $file;
}

print_r($file_container_array);
print_r($file_coil_array);

通过检查索引位置的子串,我们可以对两个阵列进行衍射:

$file_container_array = array();
$file_coil_array = array();

$files_array = $_FILES;
foreach($files_array as $key => $file)
if (strpos($key, 'file_container') !== false) {
    $file_container_array[] = $file;
} else if(strpos($key, 'file_coil') !== false) { 
    $file_coil_array[] = $file;
}

print_r($file_container_array);
print_r($file_coil_array);
您可以利用:

现在在
$result[0]
中有了所有
文件\u容器
值,在
$result[1]
中有了
文件\u线圈

您的数组可能具有可变长度,但如果它具有固定长度,则可以使用
array\u chunk

$result = array_chunk( $_FILES, 3, True );
您可以利用:

现在在
$result[0]
中有了所有
文件\u容器
值,在
$result[1]
中有了
文件\u线圈

您的数组可能具有可变长度,但如果它具有固定长度,则可以使用
array\u chunk

$result = array_chunk( $_FILES, 3, True );

你能解释一下你的真正目标吗?数组重命名的目的是什么?每个文件输入都存储在一个表中。就像把容器装进tb_容器,然后把线圈装进tb_容器,你能解释一下你的真正目标吗?数组重命名的目的是什么?每个文件输入都存储在一个表中。喜欢将容器放入tb_容器,并将其卷入tb_coilis better==0,因为字符串必须以开头,但我引用了其中的内容,并建议使用“!=”`!==false`表示存在子字符串,
但===0
表示在字符串开始时更好===0,因为字符串必须以开头,但我引用了它,并建议使用“!==”`!==false`表示存在子字符串,
但===0
表示在字符串开头