0
foreach ($_SESSION['exampleOne'] as $item)
{//insert sql

foreach ($_SESSION['exampleTwo'] as $comment)
{//insert sql

2つのforeachをマージするにはどうすればよいですか?今、私のデータベースストアはこのようになっています。

    comment | item
    ---------------
    Nice!   | Pants
    Great!  | Pants
    Awesome!| Pants
    Nice!   | Skirts
    Great!  | Skirts
    Awesome!| Skirts
    Nice!   | Shirts
    Great!  | Shirts
    Awesome!| Shirts

データベースに保存するときに、どういうわけかこのようにしたいと思います。

comment | item
---------------
Nice!   | Pants
Great!  | Skirts
Awesome!| Shirts
4

1 に答える 1

1

あなたはこのようにすることができます--

$merge = array_combine ($_SESSION['exampleOne'],$_SESSION['exampleTwo'])
foreach($merge as $key => $value)
{
    // your insert query
    $query = "insert into tableName set comment='$key', item='$value'";
}
于 2012-12-31T09:15:04.000 に答える