1

How can I retrive full name and emails in PHP? The format being received is specified as follows:

 array(2) { [0]=> array(2) { ["emails"]=> array(2) { [0]=> string(17) "[email protected]" [1]=> string(31) "www.creative-consulting-inc.com" } ["fullname"]=> string(9) "Kate Bell" } [1]=> array(2) { ["emails"]=> array(1) { [0]=> string(17) "[email protected]" } ["fullname"]=> string(14) "Daniel Higgins" } 

Edit: The Array can be of any length. Its just an example.

2 Answers 2

2

You can access array with scopes

echo $array['0']['emails']['0']; echo $array['0']['emails']['1']; echo $array['0']['fullname']; 

This will output

[email protected] www.creative-consulting-inc.com Kate Bell 

Or you can loop with a foreach

foreach($array as $arr) { foreach($arr['emails'] as $email_address) { echo $email_address; } echo $arr['fullname']; } 

This will give you all the result whithin the loop. First method instead will give you the oppurtunity to access each element only changing index

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

Comments

2

A nested foreach will give you the emails and fullname:

foreach($array as $subArray) { foreach($subArray['emails'] as $email) { echo $email; } echo $subArray['fullname']; } 

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.