我有一个来自 csv 的关联数组
Array ( [0] => Array ( [Firstname] => john [ Surname] => Smith [ Address] => Flat 1 [ Postcode] => 12345 [ Telephone] => 07777 777 777 [Email] => xxx@xxxx.xom ) [1] => Array ( [Firstname] => Robert [ Surname] => Smith [ Address] => 15 Glebe Stree [ Postcode] => g54er [ Telephone] => 07888787887 [Email] => xxxx@xxx.com )
我要做的是遍历数组并创建一个连接字符串并插入用户
$conDat = array('FirstName' => 'john',
'LastName' => 'Smith',
'Address' => 'Flat 1',
'Postcode' => '12345',
'Telephone' => '07777 777 777',
'Email' => 'xxx@xxxx.xom');
);
$conID = $app->addCon($conDat);
我遇到的问题是遍历并将键和值放入连接数据并发送它。这就是我到目前为止所拥有的。
for($i=0;$i<count($csv);$i++){
$c=0;
foreach($csv[$i] as $key=>$value){
$c++;
echo $key;echo $value;
if($c<count($csv[$i])) echo " ";
}
}
?>
编辑:
所以这就是我想要实现的
for($i=0;$i<count($csv);$i++){
$c=0;
foreach($csv[$i] as $key=>$value){
$c++;
$conData[] = array($key => $value);
if($c<count($csv[$i])) {
$conID = $app->addCon($conDat);
}
}