Trying to return an array of items from api call, the var_dump spits out the array that I want, but the return is always null. What am I missing? Many thanks
function get_all_opened($mailgun, $domain, $list_address, $items, $page_advance = false, $next_url = false)
{
$end_point = "{$domain}/events";
if($page_advance) {
$end_point = "{$domain}/events/{$next_url}";
}
//API Call
$stats = $mailgun->get($end_point, array(
'event' => 'opened',
'limit' => 25,
'list' => $list_address
));
$item_count = count($stats->http_response_body->items);
if($item_count > 0) {
$items[] = $stats->http_response_body->items;
}
if($item_count < 25) {
var_dump($items); //Correct result set
return $items; //Always NULL
}
if($item_count > 24) {
$next_parts = explode ('/', $stats->http_response_body->paging->next);
$next_url = end($next_parts);
get_all_opened($mailgun, $domain, $list_address, $items, true, $next_url);
}
}
$items = array();
get_all_opened($mailgun, $domain, $list_address, $items);