dongtao4319 2015-12-05 07:09
浏览 134

foreach循环用于许多数组插入值

hello all i have about 5 array having same no of elements and i want to insert them for each value of array into database like

 $array1 has 3 elements a1,a2,a3
 $array2 has 3 elements b1,b2,b3
 $array3 has 3 elements c1,c2,c3

now i want to insert data into database like field1=a1,field2=b1,field3=c1
 and similery for all the values saparete entry will be there

please help me achieve this i know this can be done by foreach loop of php

  • 写回答

4条回答 默认 最新

  • dongqu2863 2015-12-05 07:17
    关注

    First count the items in an array.

    As you mentioned that there are same number of elements in all the three arrays. Therefore we only need to count number of arrays in any one array. Lets take $array1 here. Use count($array1) to give element count. Suppose it gives 3 as the count.

    Now loop 3 times like below.

    for($i = 0; $i < count($array1); $i++){
        // QUERY HERE
        insert into sometable (field1, field2, field3) VALUES ($array1[$i], $array2[$i], $array3[$i]);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记