Php multi-array combination writing method this post was last edited by wjm_hi from 2013-10-2515: 55: 24. I made a score Management System // subject $ xk & nbsp; = & nbsp; array (); // grade $ nj & nbsp; = & nbsp; array (); evaluate the php multi-array combination writing method to the database
At the end of this post, wjm_hi edited my score management system at 15:55:24 on.
// Subject
$ Xk = array ();
// Grade
$ Nj = array ();
// Class
$ Bj = array ();
There are three arrays, which are generated based on the formula * grade * class, and then written to the database.
For example:
When count ($ xk) is 2, two subjects are selected.
When count ($ nj) is 3, three grades are selected.
When count ($ bj) is 7, it indicates that 7 grades are selected.
2*3*7 data records should be inserted into the database. how can this problem be achieved?
Share:
------ Solution --------------------
$xk=Array ("1","2");
$nj=Array ("1","2","3");
$bj=Array ("1","2","3","4","5","6","7");
$arr = array();
for($i=0;$i
for($j=0;$j
for($k=0;$k
$arr[] = array($xk[$i],$nj[$j],$bj[$k]);
}
}
}
foreach($arr as $row){
$sql = "INSERT INTO `examinfo` (`nj`,`bj`,`xk`) VALUES ('".$row[0]."' ,'".$row[1]."','".$row[2]."')";
}