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">
Home > Backend Development > PHP Tutorial > 如何把二维数组放到mysql中

如何把二维数组放到mysql中

WBOY
Release: 2016-06-13 10:26:25
Original
963 people have browsed it

怎么把二维数组放到mysql中.

PHP code
<!--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);
Copy after login

将A,B表对比,如果A表中有B表中没有的,将没有的数据插入B表.
我现在把共有的数据丢到arr3里去了,怎么把arr3插入B表?因为有些字段B表中没有..凌乱了..
求大神解救...

------解决方案--------------------
用 array_diff_assoc($array1, $array2); 试试
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template