三个一维数组合并成一个二维数组(PHP)
数组$Arr1=array("张三"."李四","王五")$Arr2=array("北京"."上海","深圳")$Arr3=array("工程师"."会计师","院长")...
数组
$Arr1=array("张三"."李四","王五")
$Arr2=array("北京"."上海","深圳")
$Arr3=array("工程师"."会计师","院长")
把$Arr1、$Arr2、$Arr3 实现如下
array(4) {
[0] => array {
["0"] => "张三"
["1"] => "北京"
["2"] => "工程师"
}
[1] => array {
["0"] => "李四"
["1"] => "上海"
["2"] => "会计师"
}
[2] => array {
["0"] => "王五"
["1"] => "深圳"
["2"] => "院长"
}
}
PHP该如何实现呢?懂的朋友帮忙一下,谢谢! 展开
$Arr1=array("张三"."李四","王五")
$Arr2=array("北京"."上海","深圳")
$Arr3=array("工程师"."会计师","院长")
把$Arr1、$Arr2、$Arr3 实现如下
array(4) {
[0] => array {
["0"] => "张三"
["1"] => "北京"
["2"] => "工程师"
}
[1] => array {
["0"] => "李四"
["1"] => "上海"
["2"] => "会计师"
}
[2] => array {
["0"] => "王五"
["1"] => "深圳"
["2"] => "院长"
}
}
PHP该如何实现呢?懂的朋友帮忙一下,谢谢! 展开
展开全部
$Arr4 = array();
foreach ($Arr1 as $k => $r) {
$Arr4[] = array($Arr1[$k],$Arr2[$k];$Arr3[$k]);
}
print_r($Arr4);
//如果仅仅是数字索引的话,也可以用for循环来完成的。
foreach ($Arr1 as $k => $r) {
$Arr4[] = array($Arr1[$k],$Arr2[$k];$Arr3[$k]);
}
print_r($Arr4);
//如果仅仅是数字索引的话,也可以用for循环来完成的。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询