php三维数组遍历

<?phpheader('content-type:text/html;charset=utf-8');//有以下结构的数组$array1=array('files'=>... <?php
header('content-type:text/html;charset=utf-8');

//有以下结构的数组

$array1 = array(
'files' => array(
'name' => array(
0 => 'a.gif',
1 => 'b.png',
2 => 'c.txt',
3 => 'd.css',
),
'tmp_name' => array(
0 => 'c:\windows\temp\php12.tmp',
1 => 'c:\windows\temp\php13.tmp',
2 => 'c:\windows\temp\php14.tmp',
3 => 'c:\windows\temp\php15.tmp',
),
'size' => array(
0 => 526632,
1 => 8222,
2 => 2001,
3 => 36 ,
),
'error' => array(
0 => 0,
1 => 0,
2 => 0,
3 => 0,
),
'type' => array(
0 => 'image/gif',
1 => 'image/png',
2 => 'text/plain',
3 => 'text/css',
),
)

);

//请封装函数buildInfo完成将上述函数转换成如下结构的功能.

$array2 = array(
0 => array(
'name' => 'a.gif',
'type' => 'image/gif',
'error' => 0,
'tmp_name' => 'c:\windows\temp\php12.tmp',
'size' => 526632,
'extension' => 'gif',
),
1 => array(
'name' => 'b.png',
'type' => 'image/png',
'error' => '0',
'tmp_name' => 'c:\windows\temp\php12.tmp',
'size' => 8222,
'extension' => 'png',
),
2 => array(
'name' => 'c.txt',
'type' => 'text/plain',
'error' => 0,
'tmp_name' => 'c:\windows\temp\php14.tmp',
'size' => 2001,
'extension' => 'txt',
),
3 => array(
'name' => 'd.css',
'type' => 'text/css',
'error' => 0,
'tmp_name' => 'c:\windows\temp\php15.tmp',
'size' => 36,
'extension' => 'css',
),

);
展开
 我来答
匿名用户
推荐于2016-07-11
展开全部
$array1 = array(
'files' => array(
'name' => array(
0 => 'a.gif',
1 => 'b.png',
2 => 'c.txt',
3 => 'd.css',
),
'tmp_name' => array(
0 => 'c:\windows\temp\php12.tmp',
1 => 'c:\windows\temp\php13.tmp',
2 => 'c:\windows\temp\php14.tmp',
3 => 'c:\windows\temp\php15.tmp',
),
'size' => array(
0 => 526632,
1 => 8222,
2 => 2001,
3 => 36 ,
),
'error' => array(
0 => 0,
1 => 0,
2 => 0,
3 => 0,
),
'type' => array(
0 => 'image/gif',
1 => 'image/png',
2 => 'text/plain',
3 => 'text/css',
),
)

);
$array2=array();
foreach($array1 as $key=>$value){
for($i=0;$i<sizeof($value['name']);$i++){
$array2[]=array(
'name'=>$value['name'][$i],
'type'=>$value['type'][$i],
'error'=>$value['error'][$i],
'tmp_name'=>$value['tmp_name'][$i],
'size'=>$value['size'][$i],
'extension'=>trim(strrchr($value['name'][$i],'.'),'.')
);
}
}
print_r($array2);
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式