Hocrux Hocrux - 4 months ago 7
PHP Question

Having some problems accessing items in an array

I received an array from another server, but i want to fetch the emails only.

The code:

var_dump($search_result["response"]);


It shows something like:
http://pastebin.com/LbLaQYy4

When I use:

var_dump($search_result["response"]["results"][0]["collection"]["payer"]["email"]);


I shows just one email.

How to fetch all emails ?

Answer

You'll need to loop through the returned array in order to fetch all the email addresses.

$emails = array();
foreach($search_result["response"]["results"] as $result) {
    $emails []= $result["collection"]["payer"]["email"];
}
var_dump($emails);

$emails should contain the data you're after.

Comments