2017-07-10 55 views
0

子阵值你好,我已阅读所有相关主题,发现有关如何获取循环,但并一定价值的一些解决方案,但仍无法从阵列下方得到子阵[追踪]值:获得来自阵列

[26] => 
Array ([id] => ab94b21221379be8231250962f51073d 
[sender] => [email protected] 
[total_size] => 776 
[sender_ip] => 173.212.205.208 [smtp_answer_code] => 250 [smtp_answer_code_explain] => Delivered [smtp_answer_subcode] => [smtp_answer_data] => [email protected] H=gmail-smtp-in.l.google.com [173.194.69.26] X=TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128 CV=yes K C="250 2.0.0 OK z58si11170265edc.200 - gsmtp" 
[used_ip] => 78.41.200.159 
[recipient] => [email protected] 
[subject] => Mail subject 
[send_date] => 2017-06-26 09:49:48 
[tracking] => 
      Array ( 
[click] => 0 
[open] => 1 
[client_info] => 
      Array ([0] => Array ([browser] => Firefox 11.0viaggpht.comGoo[os] => Windows [ip] => 11.111.93.76 [country] => United States [action_date] => 2017-03-27 07:59:46)))) 

我使用了standart循环来获取值[open] = 1,但从调试器得到了 Undefined index: open错误消息。是的,我得到了未定义的索引,因为我无法获得跟踪值作为子阵列。它始终在循环中询问,无论i = 1; i = k; i ++或foreach $ array的类型为$ key => $ value。

+0

为编程添加标签lang – RealCheeseLord

回答

0

您可以使用isset['open']来检查“打开”索引集或不。

您可以使用isset运营商内循环:

foreach($array as $value) 
{ 
     if(isset($value['tracking']['open'])) 
     { 
      echo $value['tracking']['open']; 
     } 
} 
+0

好的。我尝试过!is_null()但不能用'$ c = count($ smtpcheck)获得'open'项目。 ($ is = 0; $ i <$ c; $ i ++){跟踪 '] [' 开']; } break;} 它回显一个:未定义的索引,虽然我真的确定该数组只有3个级别在所需的变量之间:数组索引,值和子数组值。 –

0

你有回声不正确的值...尝试
如果(isset($ smtpcheck [$ i] [ '跟踪'] [ '开放' ])) {
echo $ smtpcheck [$ i] ['tracking'] ['open'];
}

+0

我已更正值但没有结果。需要一些时间来重建循环删除i ++方法,并且几次切换到!is_empty(),因为我的服务器几个星期前弃用了isset函数。所以现在工作。 –

+0

主题可以关闭。 –

+0

工作示例代码再次感谢Verma Kshitij https://github.com/Dignity1988/sendpulse/blob/master/book1.php –

0

我终于停止了与下面的代码:

$opened=array(); 

/*第一步:设置我们将通过主阵列使用我们的“子阵”或儿童阵列第二步循环数组终于保存工作循环中主数组值的结果。 为它们等于1且已设置的子数组值添加条件。所以我们不需要修改php.ini并选择较低级别的通知警告,这意味着收件人打开邮件。

*/ 
foreach ($smtpcheck as $sendstatus=>$value){ 
    if (isset($value['tracking']) and $value['tracking']['open']=='1') 
    { 
     $opened=$value['recipient']);// And finally printing the certain main array(one level higher but still binded to the main loop) and printing them 
print_r($opened); 
} 

我终于得到了所有打开电子邮件的收件人列表。 感谢@Kshitij Verma在正确的时间和地点提供良好的建议。我已经探索了几乎所有类似的问题来回答,并获得了上面的代码工作。没有你我就不可能。尽管如此,我仍然没有发现打印也没有保存所有的子阵列“跟踪”的选项,但用“开关”功能得到了另一个想法。 @Kshitij Verma你可以私下给我写信。我想我应该把证书添加到我正在工作的git项目中。

0
foreach ($smtpcheck as $sendstatus=>$value){ 
if (isset($value['smtp_answer_code'])){ 
switch ($sendstatus = substr($value['smtp_answer_code'], 0, 1)){ 
case "0": print_r('No message status is already fired but to early to ask status');break; 
case "1": print_r('deliverance is on the go, brothers and sisters');print_r('onthego->'); array_push($onthego,$value['recipient']);print_r($onthego); 
break; 
case "2": 
//check if value of open state of switcher is "opened" 
//check second layer of delivery to get exact knowledge of what we fucking got 
//check next if value of open state switcher is "cliked 
if (isset($value['tracking']) and $value['tracking']['open']=='1' and $value['tracking']['click']=='0'){;array_push($openedbutnotclicked, $value['recipient']);print_r('--openedbutnotclicked=>');print_r($openedbutnotclicked);break;} 
if (isset($value['tracking']) and $value['tracking']['open']=='0' and $value['tracking']['click']=='0'){;array_push($delivered, $value['recipient']);print_r('delivered');print_r($delivered);break;} 
if (isset($value['tracking']) and $value['tracking']['click']=='1'){ 
array_push($clicked, $value['recipient']);print_r($cliked);break; 
} 
case "3": print_r ('ok fine but please fill up additional fields like DATA because server requires the additional information and/or redirected your email');print_r('--not enough credentials=>');array_push($userinfo,$value['recipient']);print_r($userinfo);break; 
case "4": print_r ('check the credentials');print_r('--invalid email check the credentials=>');array_push($broken, $value['recipient']); 
break; 
case "5": print_r('--notreached->');array_push($blocked, $value['recipient']);print_r($blocked);break; 
} 
} 

在这里,我得到了几个实验。主数组“smtpcheck”包含3个级别的深度子阵列并被卸载到阵列。

};