从数组中获取子数组值

时间:2017-07-10 14:35:29

标签: php get

您好我已经阅读了所有相关主题,并找到了一些关于如何获得循环但有一定价值的解决方案,但仍无法从下面的数组中获取子数据[tracking]的值:

[26] =>
 Array ( [id] => ab94b21221379be8231250962f51073d
 [sender] => wallbreaker1@yandex.ru 
[total_size] => 776 
[sender_ip] => 173.212.205.208 [smtp_answer_code] => 250 [smtp_answer_code_explain] => Delivered [smtp_answer_subcode] => [smtp_answer_data] => someemail60@gmail.com 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] => someemail60@gmail.com
 [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 ) ) ) )

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

4 个答案:

答案 0 :(得分:0)

您可以使用isset['open']来检查"打开"索引设置与否。

您可以在循环中使用isset运算符:

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

答案 1 :(得分:0)

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

答案 2 :(得分: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项目中。

答案 3 :(得分: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个级别的深度子数组并卸载到数组中。

};