thinkphp 多维数组,变成可以插入数据库里的一维数组啊,请教~~~求助!!谢谢
array(size=3)0=>array(size=5)'username'=>string'aaa'(length=9)'dept'=>string'科技部'(len...
array (size=3)
0 =>
array (size=5)
'username' => string 'aaa' (length=9)
'dept' => string '科技部' (length=15)
'paperid' => string 'sj002' (length=5)
'busername' =>
array (size=2)
0 =>
array (size=1)
'busername' =>string 'aaa' (length=3)
1 =>
array (size=1)
'busername' =>string 'bbb' (length=3)
1 =>
array (size=5)
'username' => string 'bbb' (length=9)
'dept' => string '科技部' (length=15)
'paperid' => string 'sj002' (length=5)
'busername' =>
array (size=2)
0 =>
array (size=1)
'busername' =>string 'aaa' (length=3)
1 =>
array (size=1)
'busername' =>string 'bbb' (length=3)
2 =>
array (size=5)
'username' => string 'ccc' (length=3)
'dept' => string '一般2' (length=7)
'paperid' => string 'sj002' (length=5)
'busername' =>
array (size=1)
0 =>
array (size=1)
'busername' => string 'ccc' (length=3)
如何将这个多维数组改变成可以直接插入数据库的数组呢?求助~~~请教~~~~真心感谢~~~
array (size=5)
0 =>
array (size=5)
'username' => string 'aaa' (length=9)
'dept' => string '科技部' (length=15)
'paperid' => string 'sj002' (length=5)
'busername' => string 'aaa' (length=3)
1 =>
array (size=5)
'username' => string 'aaa' (length=9)
'dept' => string '科技部' (length=15)
'paperid' => string 'sj002' (length=5)
'busername' =>string 'bbb' (length=3)
2 =>
array (size=5)
'username' => string 'bbb' (length=9)
'dept' => string '科技部' (length=15)
'paperid' => string 'sj002' (length=5)
'busername' =>string 'aaa' (length=3)
3=>
array (size=5)
'username' => string 'bbb' (length=9)
'dept' => string '科技部' (length=15)
'paperid' => string 'sj002' (length=5)
'busername' =>string 'bbb' (length=3)
4 =>
array (size=5)
'username' => string 'ccc' (length=3)
'dept' => string '一般2' (length=7)
'paperid' => string 'sj002' (length=5)
'busername' => string 'ccc' (length=3) 展开
0 =>
array (size=5)
'username' => string 'aaa' (length=9)
'dept' => string '科技部' (length=15)
'paperid' => string 'sj002' (length=5)
'busername' =>
array (size=2)
0 =>
array (size=1)
'busername' =>string 'aaa' (length=3)
1 =>
array (size=1)
'busername' =>string 'bbb' (length=3)
1 =>
array (size=5)
'username' => string 'bbb' (length=9)
'dept' => string '科技部' (length=15)
'paperid' => string 'sj002' (length=5)
'busername' =>
array (size=2)
0 =>
array (size=1)
'busername' =>string 'aaa' (length=3)
1 =>
array (size=1)
'busername' =>string 'bbb' (length=3)
2 =>
array (size=5)
'username' => string 'ccc' (length=3)
'dept' => string '一般2' (length=7)
'paperid' => string 'sj002' (length=5)
'busername' =>
array (size=1)
0 =>
array (size=1)
'busername' => string 'ccc' (length=3)
如何将这个多维数组改变成可以直接插入数据库的数组呢?求助~~~请教~~~~真心感谢~~~
array (size=5)
0 =>
array (size=5)
'username' => string 'aaa' (length=9)
'dept' => string '科技部' (length=15)
'paperid' => string 'sj002' (length=5)
'busername' => string 'aaa' (length=3)
1 =>
array (size=5)
'username' => string 'aaa' (length=9)
'dept' => string '科技部' (length=15)
'paperid' => string 'sj002' (length=5)
'busername' =>string 'bbb' (length=3)
2 =>
array (size=5)
'username' => string 'bbb' (length=9)
'dept' => string '科技部' (length=15)
'paperid' => string 'sj002' (length=5)
'busername' =>string 'aaa' (length=3)
3=>
array (size=5)
'username' => string 'bbb' (length=9)
'dept' => string '科技部' (length=15)
'paperid' => string 'sj002' (length=5)
'busername' =>string 'bbb' (length=3)
4 =>
array (size=5)
'username' => string 'ccc' (length=3)
'dept' => string '一般2' (length=7)
'paperid' => string 'sj002' (length=5)
'busername' => string 'ccc' (length=3) 展开
3个回答
展开全部
$result = array(); // 新数组
foreach ($data as $vo) { // $data是原数组
$temp = $vo;
unset($temp['busername']);
foreach ($vo['busername'] as $v) {
$temp['busername'] = $v;
array_push($result,$temp);
}
}
你测试一下看看对不对,有问题请反馈
追问
我刚刚测试了,出来的结果是这样的:
array (size=5)
......(//这里是可以的,百度提示我字数太多,写不了。但是busername还有一层呢,插不进数据库)
'busername' =>
array (size=1)
'username'=>string 'aaa' (length=3)
追答
我知道了,你把$temp['busername'] = $v;那句改成$temp['busername'] = $v['busername'];
$result = array(); // 新数组
foreach ($data as $vo) { // $data是原数组
$temp = $vo;
unset($temp['busername']);
foreach ($vo['busername'] as $v) {
$temp['busername'] = $v['busername'];
array_push($result,$temp);
}
}
展开全部
使用foreach遍历吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
foreach 循环遍历下,应该可以的、。
追问
我。。。不会使用这个foreach循环,~~~~(>_<)~~~~ ,你能帮我写一下吗?谢谢
追答
<?php
$array = array(
0=>array(
'name'=>hao,
'age'=>21,
),
1=>array(
'name'=>buhao,
'age'=>22,
),
);
foreach($array as $v){
////$v就是个 array(
// name=>hao,
// age =>21,
// )
echo $v['name'];
echo "<hr/>";
}
?>
你试下就可以了。你就知道怎么用了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |