Reputation: 516
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.
Upvotes: 1
Views: 104
Reputation: 23490
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
Upvotes: 2
Reputation: 64526
A nested foreach
will give you the emails and fullname:
foreach($array as $subArray)
{
foreach($subArray['emails'] as $email)
{
echo $email;
}
echo $subArray['fullname'];
}
Upvotes: 2