thinkphp 多维数组,如何转成以为一维数组,然后写入数据库
array(size=2)0=>array(size=5)'username'=>string'admin'(length=5)0=>array(size=7)'dept...
array (size=2)
0 =>
array (size=5)
'username' => string 'admin' (length=5)
0 =>
array (size=7)
'dept' => string '科技部' (length=15)
'busername' => string 'admin' (length=5)
'paperdes' => string '测试' (length=9)
1 =>
array (size=7)
'dept' => string '科技部' (length=15)
'busername' => string '张三' (length=9)
'paperdes' => string '测试' (length=9)
1 =>
array (size=5)
'username' => string '张三' (length=9)
0 =>
array (size=7)
'dept' => string '科技部' (length=15)
'busername' => string 'admin' (length=5)
'paperdes' => string '测试' (length=9)
1 =>
array (size=7)
'dept' => string '科技部' (length=15)
'busername' => string '张三' (length=9)
'paperdes' => string '测试' (length=9)
现在只有将这个交叉数组变成一维数组才能使用addall插入数据库,怎么办呢?想变成这样的效果:
array (size=2)
0=>
array (size=8)
'username' => string 'admin' (length=5)
'dept' => string '科技部' (length=15)
'busername' => string 'admin' (length=5)
'paperdes' => string '测试' (length=9)
1 =>
array (size=8)
'username' => string 'admin' (length=5)
'dept' => string '科技部' (length=15)
'busername' => string '张三' (length=9)
'paperdes' => string '测试' (length=9)
2 =>
array (size=8)
'username' => string 'admin' (length=5)
'dept' => string '科技部' (length=15)
'busername' => string '李四' (length=6)
'paperdes' => string '测试' (length=9)
3 =>
array (size=8)
'username' => string 'admin' (length=5)
'dept' => string '科技部' (length=15)
'busername' => string '王五' (length=9)
'paperdes' => string '测试' (length=9)
求助~~~ 展开
0 =>
array (size=5)
'username' => string 'admin' (length=5)
0 =>
array (size=7)
'dept' => string '科技部' (length=15)
'busername' => string 'admin' (length=5)
'paperdes' => string '测试' (length=9)
1 =>
array (size=7)
'dept' => string '科技部' (length=15)
'busername' => string '张三' (length=9)
'paperdes' => string '测试' (length=9)
1 =>
array (size=5)
'username' => string '张三' (length=9)
0 =>
array (size=7)
'dept' => string '科技部' (length=15)
'busername' => string 'admin' (length=5)
'paperdes' => string '测试' (length=9)
1 =>
array (size=7)
'dept' => string '科技部' (length=15)
'busername' => string '张三' (length=9)
'paperdes' => string '测试' (length=9)
现在只有将这个交叉数组变成一维数组才能使用addall插入数据库,怎么办呢?想变成这样的效果:
array (size=2)
0=>
array (size=8)
'username' => string 'admin' (length=5)
'dept' => string '科技部' (length=15)
'busername' => string 'admin' (length=5)
'paperdes' => string '测试' (length=9)
1 =>
array (size=8)
'username' => string 'admin' (length=5)
'dept' => string '科技部' (length=15)
'busername' => string '张三' (length=9)
'paperdes' => string '测试' (length=9)
2 =>
array (size=8)
'username' => string 'admin' (length=5)
'dept' => string '科技部' (length=15)
'busername' => string '李四' (length=6)
'paperdes' => string '测试' (length=9)
3 =>
array (size=8)
'username' => string 'admin' (length=5)
'dept' => string '科技部' (length=15)
'busername' => string '王五' (length=9)
'paperdes' => string '测试' (length=9)
求助~~~ 展开
展开全部
$result = array(); // 新数组
foreach ($data as $vo) { // $data是原数组
foreach ($vo as $k => $v) {
if($k!=='username'){
$temp = $v;
$temp['username'] = $vo['username'];
array_push($result,$temp);
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询