codeigniter中未定义的索引错误

时间:2012-01-07 14:46:54

标签: codeigniter

我使用此库:http://www.in-the-attic.co.uk/2010/07/21/mailchimp-api-1-2-library-for-code-igniter/

当我这样做时:

$this->load->library('mcapi');
$this->load->config('mcapi', TRUE);

// get list members
$retval = $this->mcapi->listMembers('0000000', 'subscribed', null, 0, 5000 );

    foreach($retval as $member){
    echo $member['email']." - ".$member['timestamp']."\n";
}

我收到此错误:

A PHP Error was encountered  
Severity: Notice    
Message: Undefined index: email    
Filename: tabs/mailchimp.php    
Line Number: 18

但是当我用print_r()打印数组时,它运行正常吗? :

$retval = $this->CI->mcapi->listMembers('0000000', 'subscribed', null, 0, 5000 );
print_r($retval) ;

我得到这样的数据:

Array ( [total] => 2 [data] => Array ( [0] => Array ( [email] => email@gmail.com [timestamp] => 2012-01-06 09:29:31 ) 

有任何帮助吗? 谢谢!

1 个答案:

答案 0 :(得分:1)

你需要做<?php foreach($retval['data'] as $member) { } ?> - 包含'email'键的数组嵌套在数据数组中。