Answers.Body: <p>You could just use something like $contactData = $result['values'][0] for your var_dump to test. Your echo should be right, in theory.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-20T18:24:09.193Z
Answers.Text: Also, getSingle may be useful to you:
  
  `$result = civicrm_api3('Contact', 'getsingle', array(
    'sequential' => 1,
    'last_name' => "Tobias",
    'first_name' => "Randy",
    'id' => 4,
  ));`
Answers.UserDisplayName: Randy Tobias
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-21T22:18:19.537Z
Answers.Text: thanks for pointing me in the right direction, guys. This did the trick:
  
  $contactData = $result['values'][0]['contact_id'];
  echo "Contact ID: " . $contactData;
Answers.UserDisplayName: MtnPavlas
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-20T17:53:36.117Z
Answers.LastActivityDate: 2017-04-20T17:53:36.117Z
Answers.UserDisplayName: Randy Tobias
Body: <p>how can I access the values in a nested array, e.g. when using get for contact entity
  e.g. how can I adjust the following to get the first name? (not working for me at the moment)</p>
  
  <pre><code>$result = civicrm_api3('Contact', 'get', array(
     'sequential' =&gt; 1,
     'return' =&gt; array("first_name", "last_name", "email"),
     'id' =&gt; 28296
  ));
  echo $result['values'][0]['first_name'];
  </code></pre>
  
  <p>if I use var_dump ($result) I get the following so the results are there:</p>
  
  <p>array(5) { ["is_error"]=> int(0) ["version"]=> int(3) ["count"]=> int(1) ["id"]=> int(28296) ["values"]=> array(1) { [0]=> array(6) { ["contact_id"]=> string(5) "28296" ["first_name"]=> string(8) "Thirteen" ["last_name"]=> string(4) "Test" ["email_id"]=> string(5) "27750" ["email"]=> string(25) "thirteen.test@artigma.com" ["id"]=> string(5) "28296" } } }</p>
  
  <p>thanks much!</p>
  
Tags: <api>
Title: how to access nested array
ThreadText: # how to access nested array
  
  (Asked by: username_0 on 2017-04-20)
  
  how can I access the values in a nested array, e.g. when using get for contact entity
  e.g. how can I adjust the following to get the first name? (not working for me at the moment)
  $result = civicrm_api3('Contact', 'get', array(
     'sequential' => 1,
     'return' => array("first_name", "last_name", "email"),
     'id' => 28296
  ));
  echo $result['values'][0]['first_name'];
  
  if I use var_dump ($result) I get the following so the results are there:
  array(5) { ["is_error"]=> int(0) ["version"]=> int(3) ["count"]=> int(1) ["id"]=> int(28296) ["values"]=> array(1) { [0]=> array(6) { ["contact_id"]=> string(5) "28296" ["first_name"]=> string(8) "Thirteen" ["last_name"]=> string(4) "Test" ["email_id"]=> string(5) "27750" ["email"]=> string(25) "thirteen.test@artigma.com" ["id"]=> string(5) "28296" } } }
  thanks much!
  
  **Tags:** api
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-04-20. Score: 1 | Accepted answer
  
  You could just use something like $contactData = $result['values'][0] for your var\_dump to test. Your echo should be right, in theory.
  
  > **Comments:**
  > **username_1**: Also, getSingle may be useful to you:  `$result = civicrm_api3('Contact', 'getsingle', array(   'sequential' => 1,   'last_name' => "Tobias",   'first_name' => "Randy",   'id' => 4, ));`  
  > **username_0**: thanks for pointing me in the right direction, guys. This did the trick:  $contactData = $result['values'][0]['contact_id']; echo "Contact ID: " . $contactData;  
  
  ---
  
  