0

データベースに挿入する必要があるこの配列があります。以下のコードは機能しません。同じ値になってしまいます。

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"
}
4

1 に答える 1

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
}
于 2012-06-18T16:55:33.590 に答える