如何将一维数组的值作为二维数组的键名(PHP)
1个回答
展开全部
<?php
$a = array(//二维数组
1=>array( 0=>array("php01","php02","php03"),
1=>array("php11","php12","php13")
),
6=>array( 0=>array("AJAX601","AJAX602","AJAX603"),
1=>array("AJAX611","AJAX612","AJAX613")
),
2=>array( 0=>array("MYSQL01","MYSQL02","MYSQL03"),
1=>array("MYSQL11","MYSQL12","MYSQL13")
)
);
$b = array('PHP', 'AJAX', 'MYSQL');//一维数组
$c = array_combine($b, $a);
echo '<pre>';
print_r($c);
echo '</pre>';
?>
///////////////////////////////////////////////////////////////////////////////////
输出结果:
Array
(
[PHP] => Array(
[0] => Array(
[0] => php01
[1] => php02
[2] => php03
)
[1] => Array(
[0] => php11
[1] => php12
[2] => php13
)
)
[AJAX] => Array(
[0] => Array(
[0] => AJAX601
[1] => AJAX602
[2] => AJAX603
)
[1] => Array(
[0] => AJAX611
[1] => AJAX612
[2] => AJAX613
)
)
[MYSQL] => Array(
[0] => Array(
[0] => MYSQL01
[1] => MYSQL02
[2] => MYSQL03
)
[1] => Array(
[0] => MYSQL11
[1] => MYSQL12
[2] => MYSQL13
)
)
)
$a = array(//二维数组
1=>array( 0=>array("php01","php02","php03"),
1=>array("php11","php12","php13")
),
6=>array( 0=>array("AJAX601","AJAX602","AJAX603"),
1=>array("AJAX611","AJAX612","AJAX613")
),
2=>array( 0=>array("MYSQL01","MYSQL02","MYSQL03"),
1=>array("MYSQL11","MYSQL12","MYSQL13")
)
);
$b = array('PHP', 'AJAX', 'MYSQL');//一维数组
$c = array_combine($b, $a);
echo '<pre>';
print_r($c);
echo '</pre>';
?>
///////////////////////////////////////////////////////////////////////////////////
输出结果:
Array
(
[PHP] => Array(
[0] => Array(
[0] => php01
[1] => php02
[2] => php03
)
[1] => Array(
[0] => php11
[1] => php12
[2] => php13
)
)
[AJAX] => Array(
[0] => Array(
[0] => AJAX601
[1] => AJAX602
[2] => AJAX603
)
[1] => Array(
[0] => AJAX611
[1] => AJAX612
[2] => AJAX613
)
)
[MYSQL] => Array(
[0] => Array(
[0] => MYSQL01
[1] => MYSQL02
[2] => MYSQL03
)
[1] => Array(
[0] => MYSQL11
[1] => MYSQL12
[2] => MYSQL13
)
)
)
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询