Warning: Invalid argument supplied for foreach()

I am creating an application that uses the MailChimp v3 API, I send off a query to grab all the lists, then I iterate over that array and then iterate over the arrays inside to grab each individual ID and add them to an array. This works perfectly and I get an array with all the correct ID's however I get this error.

Warning: Invalid argument supplied for foreach()

Am I doing something wrong here? Even though I am getting the correct data

Here is the data a var dump returns on all the lists, I have taken out the data for security reasons but left the format.

http://pastebin.com/qCSkUmL3

Below is my code

// Create an array to store each list ID in so we can query it using the API
$listIDs = array();

// test to grab all the lists
$allLists = $MailChimp->get('lists');

foreach ( $allLists as $list ) {

    foreach ( $list as $singleList ) {

        if ( isset($singleList['id'] ) ) {

            $listIDs[] = $singleList['id'];

        } 
    }
}

Can you print_r your $allLists? That'd make it easier.

From what I understand, maybe you should change this line:

foreach ( $allLists as $list ) {

To

foreach ( $allLists['lists'] as $list ) {
链接地址: http://www.djcxy.com/p/53064.html

上一篇: 为foreach()提供的参数无效,找不到合适的解决方案

下一篇: 警告:为foreach()提供的参数无效