我有一个格式如下的表单字段。
echo '<pre>';
print_r($_REQUEST);
echo '</pre>';exit;
[customer_id] = [0=> 4,1=>5];
[hobies]=>[0=> circket,1=>chess];
这里我想转换为多维关联数组。
$output = [
4=>[
'hobies'=>'circket'
],
5=>[
'hobies'=> 'chess'
]
];
感谢和圣诞快乐
答案 0 :(得分:-2)
<?php
$customer_id = array(4, 5);
$hobies = array('circket', 'chess');
$output = array();
foreach($customer_id as $index=>$cid){
$output[$customer_id[$index]] = array("hobies"=>$hobies[$index]);
}
var_dump($output);
输出为
array(2) {
[4]=>
array(1) {
["hobies"]=>
string(7) "circket"
}
[5]=>
array(1) {
["hobies"]=>
string(5) "chess"
}
}