Created
January 11, 2014 17:41
-
-
Save ksnider/8374125 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // 80/20 PHP - Day Three | |
| // http://api-demo.com/scripts/arrays.php | |
| /* Example from the handout | |
| $myFarm =array( | |
| 'horses' =>array( | |
| 'old_horse' => 'Cashmere', | |
| 'young_horse' => 'RugRat', | |
| 'mean_horse' => 'Carolina' | |
| ), | |
| 'dogs' => array( | |
| 'german_shepherd' => 'Ohne', | |
| 'ditch_dog' => 'Rose' | |
| ), | |
| 'people' => array( | |
| 'husband' => 'Jim', | |
| 'wife' => 'Kim' | |
| ) | |
| ); | |
| echo "<pre>"; | |
| print_r($myFarm); | |
| echo "</pre>"; | |
| $jim = $myFarm['people']['husband']; | |
| echo "My husband's name is " . $myFarm['people']['husband']; | |
| */ | |
| require("isdk.php"); | |
| $app = new iSDK; | |
| if ($app->cfgCon("sandbox")) { | |
| // Current date in Infusionsoft-friendly format | |
| echo "You connected at " . $currentDate = date("Ymd\TH:i:s") . "<br/>"; | |
| // Simple Array | |
| $contactId = 129; // you will need to change this value | |
| $returnFields = array('Email'); // this is a simple array | |
| echo $returnfields[0] . '<br/>'; | |
| // Associative Array Example #1 | |
| $conDat = $app->loadCon($contactId, $returnFields); | |
| echo "<pre>"; | |
| print_r($conDat); // the call returns an associative array | |
| echo "</pre>"; | |
| $email = $conDat['Email']; | |
| echo 'Email: ' . $email . '<br/><br/>'; | |
| // Associative Array Example #2 | |
| $update = array('Username' => $email, | |
| 'Company' => 'Train and Simple'); // this one takes associative array as arg | |
| $conID = $app->updateCon($contactId, $update); | |
| var_dump($conID); | |
| echo '<br/><br/>'; | |
| // Nested Arrays | |
| $returnFields = array('Id','FirstName','LastName'); // simple array | |
| $query = array('LastName' => 'Dawg'); // associative array | |
| $contacts = $app->dsQuery("Contact",10,0,$query,$returnFields); | |
| echo "<pre>"; | |
| print_r($contacts); | |
| echo "</pre>"; | |
| echo 'ID: ' .$contacts[0]['Id'] . '<br/>'; | |
| echo 'First Name: ' .$contacts[0]['FirstName'] . '<br/>'; | |
| echo 'Last Name: ' .$contacts[0]['LastName'] . '<br/><br/>'; | |
| echo 'First Dog: ' .$contacts[0]['FirstName'] . '<br/>'; | |
| echo 'Second Dog: ' .$contacts[1]['FirstName'] . '<br/>'; | |
| echo 'Third Dog: ' .$contacts[2]['FirstName'] . '<br/>'; | |
| } else { | |
| echo "Not Connected..."; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment