-1

I have an associative array from a 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 ) 

What I am tying to do is loop through the array and create a connection string and insert the users

$conDat = array('FirstName' => 'john',
          'LastName'  => 'Smith',
          'Address'     => 'Flat 1',
          'Postcode' => '12345',
          'Telephone' => '07777 777 777',
          'Email' => 'xxx@xxxx.xom'); 


);


$conID = $app->addCon($conDat);

The problem I am having is iterating through and putting the key and value into the connection Data and sending it. This is what I have so far.

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 " ";

    }
}
?> 

EDIT:

so this is what I am trying to achieve

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

    }

}
LeBlaireau
  • 17,133
  • 33
  • 112
  • 192
  • 1
    What "connection" are you talking about? – deceze Apr 04 '14 at 09:50
  • Can you provide an example of the output you expect? – Jim Apr 04 '14 at 09:52
  • http://help.infusionsoft.com/api-docs/dataservice this is the api if you look at the add method. i need to loop through every user and insert it – LeBlaireau Apr 04 '14 at 09:54
  • Very poorly worded question. I have no idea what you're trying to achieve, or what form of answer you are expecting. To start with, you need to explain what the function `addCon` does, and whether it adds data column by column, or row by row. – cartbeforehorse Apr 04 '14 at 10:04

1 Answers1

0

Without testing i think this might be it:

foreach($csv as $conection){
    foreach($conection as $key=>$value){
        $conData = array($key => $value);
        $conID = $app->addCon($conData);
    }
}
FabioG
  • 2,936
  • 3
  • 31
  • 50