PHP多维数组排列
array(size=11)'tihao'=>array(size=3)0=>string'1'(length=1)1=>string'1'(length=1)2=>st...
array (size=11)
'tihao' =>
array (size=3)
0 => string '1' (length=1)
1 => string '1' (length=1)
2 => string '2' (length=1)
'biaoti' =>
array (size=3)
0 => string '677' (length=3)
1 => string '旅游团' (length=9)
2 => string '' (length=0)
'shangchuanrenid' =>
array (size=1)
0 => string '105' (length=3)
将此数组,排列成,
array (size=3)
0 =>
array (size=40)
'id' => string 'xx' (length=2)
'tianjiashijian' => string '1403240745' (length=10)
'biaoti' => string '677' (length=3)
'shijuanid' => string '24' (length=2)
'neirong' => string ' 考题内容7777' (length=17)
'dati' => null
'daan' => string ' 考题内容777' (length=16)
1 =>
array (size=40)
'id' => string '66' (length=2)
'tianjiashijian' => string '1403674927' (length=10)
'biaoti' => string 'xx' (length=9)
'shijuanid' => string '24' (length=2)
'pid' => string '21' (length=2)
'daan' => string '7676' (length=4)
'xuanxiang1' => string 'on' (length=2)
3=>
array (size=40)
'id' => string '66' (length=2)
'tianjiashijian' => string '1403674927' (length=10)
'biaoti' => string 'xx' (length=9)
'shijuanid' => string '24' (length=2)
'pid' => string '21' (length=2)
'daan' => string '7676' (length=4)
'xuanxiang1' => string 'on' (length=2)
内容是我随便写的,重点是排列成一个新的数组,便于写入数据库。需要排列的数组是HTML多表单提交上来的,求数组的排列方法,或是多表单提交的方法。感激不尽。 展开
'tihao' =>
array (size=3)
0 => string '1' (length=1)
1 => string '1' (length=1)
2 => string '2' (length=1)
'biaoti' =>
array (size=3)
0 => string '677' (length=3)
1 => string '旅游团' (length=9)
2 => string '' (length=0)
'shangchuanrenid' =>
array (size=1)
0 => string '105' (length=3)
将此数组,排列成,
array (size=3)
0 =>
array (size=40)
'id' => string 'xx' (length=2)
'tianjiashijian' => string '1403240745' (length=10)
'biaoti' => string '677' (length=3)
'shijuanid' => string '24' (length=2)
'neirong' => string ' 考题内容7777' (length=17)
'dati' => null
'daan' => string ' 考题内容777' (length=16)
1 =>
array (size=40)
'id' => string '66' (length=2)
'tianjiashijian' => string '1403674927' (length=10)
'biaoti' => string 'xx' (length=9)
'shijuanid' => string '24' (length=2)
'pid' => string '21' (length=2)
'daan' => string '7676' (length=4)
'xuanxiang1' => string 'on' (length=2)
3=>
array (size=40)
'id' => string '66' (length=2)
'tianjiashijian' => string '1403674927' (length=10)
'biaoti' => string 'xx' (length=9)
'shijuanid' => string '24' (length=2)
'pid' => string '21' (length=2)
'daan' => string '7676' (length=4)
'xuanxiang1' => string 'on' (length=2)
内容是我随便写的,重点是排列成一个新的数组,便于写入数据库。需要排列的数组是HTML多表单提交上来的,求数组的排列方法,或是多表单提交的方法。感激不尽。 展开
2个回答
展开全部
我写了个例子,应该可以满足你的需求
$array = array(
'id' => array(1,2,3),
'name' => array('name1', 'name2', 'name3'),
'age' => array(18,19,20)
);
$new_array = array();
foreach($array as $field => $data){
foreach($data as $key => $value){
$new_array[$key][$field] = $value;
}
}
print_r($new_array);
exit;
如有问题,请追问。
更多追问追答
追问
$array = array(
'id' => array(1,2,3),
'name' => array('name1', 'name2', 'name3'),
'age' => array(18,19,20),
'zhili' => array(99);
怎样填充'zhili'到每个数组中.
追答
<?php
$array = array(
'id' => array(1,2,3),
'name' => array('name1', 'name2', 'name3'),
'age' => array(18,19,20),
'zhili' => array(1,99)
);
$count = count($array['id']); //以id为基准
$new_array = array();
foreach($array as $field => $data){
foreach($data as $key => $value){
$new_array[$key][$field] = $value;
}
while($key < $count -1){
$key++;
$new_array[$key][$field] = $data[0]; //填充值为第一个
//$new_array[$key][$field] = $value; //填充值为最后一个
}
}
print_r($new_array);
exit;
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询