PHP数组到SQL [英] php array to SQL
本文介绍了PHP数组到SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$array = array
(
53 => array('num' => 20,'name' => 'aaa'),
10 => array('num' => 20,'name' => 'bbb')
);
$ SQL =INSENT INTO数据(ID,NUM,名)VALUES ('53','20','AAA'),('10','20','BBB' )
如何$阵列转换('53','20','AAA'),('10','20','BBB')
?
感谢
推荐答案
破灭()可以帮助你做到这一点,虽然你会需要通过循环并将其应用到每个阵列:
implode() can help you do this, though you will need to loop through and apply it to each individual array:
$resultStrings = array();
foreach ($array as $key => $values) {
$subarrayString = "('$key','" . implode($values, "','") . "')";
$resultStrings[] = $subarrayString;
}
$result = implode($resultStrings, ",");
这篇关于PHP数组到SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文