<?php
$arr = [
'name' =>
[
'打豆豆',111,111
],
'jine' => [
'111','111','111'
],
'renshu' => [
11,111,11
]
];
// 整理数组
$settle_array = [];
$count = count($arr);
$i = 0;
while ( $i < $count) {
$settle_array[] = [
'name' => $arr['name'][$i],
'jine' => $arr['jine'][$i],
'renshu' => $arr['renshu'][$i],
];
++$i;
}
// 数据入库
insertMore($settle_array);
function insertMore(array $param)
{
$keys = [];
$values = [];
$fill = '';
$data = [];
foreach ($param as $param_key => $param_val) {
foreach($param_val as $child_key => $child_val){
array_push($values,$child_val);
}
if( is_array($param_val)){
$fill.= '('.implode(',', array_fill(0, count($param_val), '?')).'),';
}
}
$sql = 'INSERT INTO `'.$this->table.'` ('.implode(',', array_keys($param[0])).') VALUES '.trim($fill,',');
$stmt = $this->pdo->prepare($sql);
$stmt->execute($values);
$this->errorInfo = $stmt->errorInfo();
return $this->getLastInsertId();
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…