2017-07-10 82 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個級別的深度子陣列並被卸載到陣列。

};