2014-04-04 175 views
-1

我有一個關聯數組從csv循環關聯數組PHP

Array ([0] => Array ([Firstname] => john [ Surname] => Smith [ Address] => Flat 1 [ Postcode] => 12345 [ Telephone] => 07777 777 777 [Email] => [email protected]) [1] => Array ([Firstname] => Robert [ Surname] => Smith [ Address] => 15 Glebe Stree [ Postcode] => g54er [ Telephone] => 07888787887 [Email] => [email protected]) 

我所搭售做的是循環遍歷數組,然後建立一個連接字符串,並插入用戶

$conDat = array('FirstName' => 'john', 
      'LastName' => 'Smith', 
      'Address'  => 'Flat 1', 
      'Postcode' => '12345', 
      'Telephone' => '07777 777 777', 
      'Email' => '[email protected]'); 


); 


$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); 

    } 

} 
+1

什麼 「連接」 是你談論? – deceze

+0

您能否提供您期望的輸出示例? – Jim

+0

http://help.infusionsoft.com/api-docs/dataservice如果你看看add方法,這是api。我需要遍歷每個用戶並插入它 – LeBlaireau

回答

0

未經測試,我認爲這可能是它:

foreach($csv as $conection){ 
    foreach($conection as $key=>$value){ 
     $conData = array($key => $value); 
     $conID = $app->addCon($conData); 
    } 
}