5個數組同時寫到資料庫怎麼寫?

來源:互聯網
上載者:User
$_POST['a'] 值為1,2,3,4,5
$_POST['b'] 值為a,b,c,d,e
$_POST['c'] 值為6,7,8,9,0
$_POST['d'] 值為h,i,j,k,l
$_POST['e'] 值為o,p,q,r,s

這五個數組同時是從裡接收過來的。現在我要把它們都寫入到資料庫裡,迴圈應該怎麼寫? foreach貌似只能針對一個數組。


最後寫到資料庫的格式應該是
第一條:1 a 6 h i
第二條:2 b 7 i p
第三條:3 c 8 j q
第四條:4 d 9 k r
第五條:5 e 0 l s


回複討論(解決方案)

foreach($_POST['a'] as $i=>$a) {  $b = $_POST['b'];  $d = $_POST['c'];  $d = $_POST['d'];  $e = $_POST['e'];  //與 $a,$b,$c,$d,$e 相關的操作}

也可以
foreach(array_map(null, $_POST['a'], $_POST['b'], $_POST['c'], $_POST['d'], $_POST['e']) as $r) {  //對 $r 的相關操作}

foreach($_POST['a'] as $i=>$a) {  $b = $_POST['b'];  $d = $_POST['c'];  $d = $_POST['d'];  $e = $_POST['e'];  //與 $a,$b,$c,$d,$e 相關的操作}

也可以
foreach(array_map(null, $_POST['a'], $_POST['b'], $_POST['c'], $_POST['d'], $_POST['e']) as $r) {  //對 $r 的相關操作}




我每一列在資料庫中都對應一列,這樣子貌似不好一條一條的寫入了

你自己看看迴圈中得到的都是什麼

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.