为什么print_r后会多出数组
function getFile() {
$i = 0;
foreach ( $_FILES as $file ) {
if (is_string ( $file ['name'] )) {
$file [$i] = $file;
$i ++;
} elseif (is_array ( $file ['name'] )) {
foreach ( $file['name'] as $key => $val ) {
$file [$i] ['name'] = $file ['name'] [$key];
$file [$i] ['type'] = $file ['type'] [$key];
$file [$i] ['tmp_name'] = $file ['tmp_name'] [$key];
$file [$i] ['error'] = $file ['error'] [$key];
$file [$i] ['size'] = $file ['size'] [$key];
$i ++;
}
}
}
return ($file);
}
Array
(
[name] => Array
(
[0] => b.jpeg
[1] => Lighthouse.jpg
[2] => Tulips.jpg
[3] => Lighthouse.jpg
)
[type] => Array
(
[0] => application/octet-stream
[1] => image/jpeg
[2] => image/jpeg
[3] => image/jpeg
)
[tmp_name] => Array
(
[0] => D:\wamp\tmp\php6162.tmp
[1] => D:\wamp\tmp\php6163.tmp
[2] => D:\wamp\tmp\php6174.tmp
[3] => D:\wamp\tmp\php6185.tmp
)
[error] => Array
(
[0] => 0
[1] => 0
[2] => 0
[3] => 0
)
[size] => Array
(
[0] => 5
[1] => 561276
[2] => 620888
[3] => 561276
)
[0] => Array
(
[name] => b.jpeg
[type] => application/octet-stream
[tmp_name] => D:\wamp\tmp\php6162.tmp
[error] => 0
[size] => 5
)
[1] => Array
(
[name] => Lighthouse.jpg
[type] => image/jpeg
[tmp_name] => D:\wamp\tmp\php6163.tmp
[error] => 0
[size] => 561276
)
[2] => Array
(
[name] => Tulips.jpg
[type] => image/jpeg
[tmp_name] => D:\wamp\tmp\php6174.tmp
[error] => 0
[size] => 620888
)
[3] => Array
(
[name] => Lighthouse.jpg
[type] => image/jpeg
[tmp_name] => D:\wamp\tmp\php6185.tmp
[error] => 0
[size] => 561276
)
)