douyan1244 2019-02-23 12:30
浏览 245
已采纳

如何在php中的foreach循环中使用两个数组或三个数组来插入数据库

How to insert multiple arrays with a foreach in rows of databases?

It's not a problem with an array, but my problem is to use two arrays or more.

my php code:

$checkBox1 = implode(',', $_POST['goinput1']);
$checkBox2 = implode(',', $_POST['goinput3']);
$mark3=explode(',', $checkBox1);
$mark4=explode(',', $checkBox2);
foreach($mark3 as $out3) 
{
    $sql_sub = "INSERT INTO sub_forms
                        (bord_mizban,bord_mihman) 
                VALUES ('$out3','$out4')";      
    if ($conn->query($sql_sub) === TRUE) {  

    } else {

    }   

}

** I want the out 4 variable insert to the database with the out 3 variable **

  • 写回答

2条回答 默认 最新

  • dongyi6543 2019-02-23 12:49
    关注

    Iterate over $mark3 using indexes ($key) and get element under same key:

    foreach($mark3 as $key => $out3) 
    {
        echo $out3 . '; ' . $mark4[$key];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?