我有来自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);
}
}
答案 0 :(得分:0)
如果没有测试,我认为可能就是这样:
foreach($csv as $conection){
foreach($conection as $key=>$value){
$conData = array($key => $value);
$conID = $app->addCon($conData);
}
}