$array = array ( 53 => array('num' => 20,'name' => 'aaa'), 10 => array('num' => 20,'name' => 'bbb') );
$ sql =“ INSENT INTO data(id,num,name)VALUES ('53','20','aaa'),('10','20','bbb')”;
('53','20','aaa'),('10','20','bbb')
如何将$ array转换成('53','20','aaa'),('10','20','bbb')?
谢谢
implode()可以帮助您做到这一点,尽管您将需要遍历并将其应用于每个单独的数组:
$resultStrings = array(); foreach ($array as $key => $values) { $subarrayString = "('$key','" . implode($values, "','") . "')"; $resultStrings[] = $subarrayString; } $result = implode($resultStrings, ",");