<?php

set_time_limit(0);
//================== mailchimp.com ==========================
require_once 'MCAPI.class.php';
$apikey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxx';
// Enter your API key from MailChimp
$api = new MCAPI($apikey);
//================== Pipelinedeals.com  =====================
require_once 'PDAdapter.php';
$conditions = null;
$page = null;
$_postback = null;
$api_key = 'xxxxxxxxxxxxxxxxxxxxx';
// Enter your API key from Pipelinedeals
$pda = new PDAdapter($api_key);
//================== get data from Pipelinedeals ======================
$lead_sources = array(200344, 443356, 528827);
// Put details that you want to select from Pipelinedeals
$resources = "people";
$conditions['person_type'] = 'Lead';
// for instance "Lead"
$pda->setMethod('get');
$result = $pda->doRequest($resources, $conditions, $page, $_postback);
$pages = 3;
// $result['pagination']['pages'];
$stack = array();
if ($pages > 0) {
    foreach ($lead_sources as $type) {
        $conditions['lead_source'] = $type;
        for ($i = 1; $i <= $pages; $i++) {