我有这个数组,我需要插入数据库。 我的下面的代码不起作用,我最终得到了相同的值。
array(10) { [0]=> array(1) { ["GymnastName"] => string(7) "ertwert" }
[1]=> array(1) { ["GymnastName"] => string(6) "wergfb" }
[2]=> array(1) { ["GymnastAge"] => string(8) "ewrtwert" }
[3]=> array(1) { ["GymnastAge"] => string(8) "dsfvsdtg" }
[4]=> array(1) { ["ParentsName"] => string(9) "werfgdsfv" }
[5]=> array(1) { ["ParentsName"] => string(9) "wetrgwerg" }
[6]=> array(1) { ["ParentsEmail"] => string(7) "erteqrt" }
[7]=> array(1) { ["ParentsEmail"] => string(6) "adfwer" }
[8]=> array(1) { ["ParentsPhone"] => string(7) "ertwert" }
[9]=> array(1) { ["ParentsPhone"]=> string(4) "qert" }
}
这是我的循环:
for ($i=0; $i<$l; $i++) {
$name = $gymarray[$i];
$age = $gymarray[$i];
$parentname = $gymarray[$i];
$parentemail = $gymarray[$i];
$parentphone = $gymarray[$i];
$db->insert statement here
基本上我需要将记录插入GymnastName,GymnastAge,ParentsName,ParentsEmail,ParentsPhone。
最终代码的最终结果是:
array(1) {
["GymnastName"]=>
string(7) "ertwert"
}
array(1) {
["GymnastName"]=>
string(7) "ertwert"
}
array(1) {
["GymnastName"]=>
string(7) "ertwert"
}
array(1) {
["GymnastName"]=>
string(7) "ertwert"
}
array(1) {
["GymnastName"]=>
string(7) "ertwert"
}
答案 0 :(得分:2)
我想你想做点什么
for ($i=0; $i<$l; $i) {
$name = $gymarray[$i]["GymnastName"];
$age = $gymarray[$i + 2]["GymnastAge"];
$parentname = $gymarray[$i + 4]["GymnastAge"];
$parentemail = $gymarray[$i + 6]["ParentsEmail"];
$parentphone = $gymarray[$i + 8]["ParentsPhone"];
$db->insert statement here
}