数组用php插入mysql数据库

http://www.oschina.net/question/2243780_172861


$a = array (
        '西瓜' => 'xigua',
        '橘子' => 'juzi'
);
 
$value_str = '';
foreach ( $a as $key => $val ) {
    $value_str [] = "'" . $key . "','" . $val . "'";
}
$s="insert into table_name (`name`,`pinyin`) values ("
         .implode ( "),(", $value_str ) . ")";
echo $s;


你可能感兴趣的:(数组用php插入mysql数据库)