0

I have an array which i get like this:

$tet = $SimplicateApi->makeApiCall('GET','/crm/person?q[first_name]=Kevin1'); 

I wanted to see all the array keys inside the array so i did

print_r(array_keys($tet['data']['0'])); 

The Results:

Array ( [0] => id [1] => interests [2] => simplicate_url [3] => avatar [4] => linked_as_contact_to_organization [5] => gender [6] => first_name [7] => family_name [8] => full_name [9] => email [10] => phone ) 

My question is how do i check whats inside in for example first_name

5
  • 1
    print_r($tet['data']['0']['first_name']);? Commented Nov 30, 2016 at 13:31
  • Check the edit for your question. You can see that there is not first_name [7]. You array has they key 6 and it's value is first_name (7 is the family_name). Commented Nov 30, 2016 at 13:35
  • Thanks @RuslanOsmanov this worked, what does the ['0'] do ? Commented Nov 30, 2016 at 13:35
  • 1
    @Kevin.a, this is the way to access an array item at index zero. In this case $tet['data'] is the array. Commented Nov 30, 2016 at 13:36
  • awesome @RuslanOsmanov thanks :) Commented Nov 30, 2016 at 13:37

2 Answers 2

2

array_keys($array) returns an array of $array keys.


Since the result of array_keys($tet['data']['0']) contains first_name, we can access the value with the [] operator as follows:

print_r($tet['data']['0']['first_name']); 

In this code we access $tet['data']['0'] array by 'first_name' key.

Sign up to request clarification or add additional context in comments.

Comments

1

var_dump full array and see all keys and their values in one shot:

echo '<pre>'; var_dump($tet['data']['0']); echo '</pre>'; 

To have more insight, var_dump original array to get full info about it:

echo '<pre>'; var_dump($tet); echo '</pre>'; 

So that you may know why you have to use data key and the 0 key. <pre> tag is just used to have nice output.

I hope it helps

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.