[How to write four arrays to the database at the same time ?] $ _ POST [a] & nbsp; value: 1, 2, 4, 4, 5 $ _ POST [B] & nbsp; the value is a, B, c, d, e $ _ POST [c] & nbsp; & nbs [how to write four arrays to the database at the same time?]
$ _ POST ['A'] value: 1, 2, 3, 4, 5
$ _ POST ['B'] value: a, B, c, d, e
$ _ POST ['c'] values: male, female, female, male, and male
$ _ POST ['D'] values: 25, 26, 27, 26
The four arrays are . Now I want to write them all into the database. how should I write the loop?
The last format written to the database should be
No. name gender age
Article 1: 1 a male 25
Article 2: 2 B female 26
Article 3: 3 c women 27
Article 4: 4 d male 26
Article 5: 5 e male 26
------ Solution --------------------
$ _ POST ['A'] = '1, 2, 3, 4, 5 ';
$ _ POST ['B'] = "a, B, c, d, e ";
$ _ POST ['c'] = "male, female, female, male ";
$ _ POST ['D'] = "25, 26, 27, 26 ";
$ A = explode (',', $ _ POST ['A']);
$ B = explode (',', $ _ POST ['B']);
$ C = explode (',', $ _ POST ['c']);
$ D = explode (',', $ _ POST ['D']);
Foreach ($ a as $ key => $ value ){
$ SQL = "inser into tbl_name values ('$ value',' {$ B [$ key]} ',' {$ c [$ key]} ', '{$ d [$ key]}'); ";
// Mysql_query ($ SQL );
Echo $ SQL, PHP_EOL;