query($sql);while($row=mysql_fetch_array($result)){ $arr["id"][]=$row["id"]; $a"/> query($sql);while($row=mysql_fetch_array($result)){ $arr["id"][]=$row["id"]; $a">
Maison >développement back-end >tutoriel php >如何把二维数组放到mysql中
怎么把二维数组放到mysql中.
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$sql="select * from a";$result=$db->query($sql);while($row=mysql_fetch_array($result)){ $arr["id"][]=$row["id"]; $arr["no"][]=$row["no"]; $arr["name"][]=$row["name"]; }$sql2="select * from b";$result2=$db->query($sql2);while($row=mysql_fetch_array($result2)){ $arr2["id"][]=$row["id"]; $arr2["address"][]=$row["address"];}function array_diff_rewrite($array1, $array2){ //遍历$content中的key foreach($array1 as $k=>$v) { //判断array2数组中是否有与array1中相同的key,不存在则赋予 if(!isset($array2[$k])) { $array2[$k]=$array1[$k]; } } return $array2;}$arr3=array_diff_rewrite($arr,$arr2);//print_r($arr3);function insert($array1,$array2){ foreach ($array1 as $k=>$v){ if(!isset($array2[$k])) { $sql4="alter table b add $k varchar(200)"; }}echo $sql4;}insert($arr3, $arr2);