[英]function inside FOR LOOP execute only once
我有一系列需要驗證的電子郵件。 當我在迭代過程中調用該函數時,循環將在第一次迭代后停止,並且不會在整個數組上進行。 和返回值。
$ num包含6,而$ email組成的(1st @ yahoo.com,2nd @ yahoo.com,3rd @ yahoo.com,4th@yahoo.com,5th @ yahoo.com,6th @ yahoo.com)是唯一有效的和注冊的電子郵件分別是1st@yahoo.com和6th@yahoo.com,但是我只能獲得最后的6th@yahoo.com。
function get_email_verification(){
$num = count($this->get_payqucker_emails());
$email = $this->get_payqucker_emails();
if ($num){
for($i=0; $i < $num; $i++){
$api_request_url = "http://api.payquicker.com/api/IsActiveAccount";
$param = "email=".$email[$i];
$result_request = $this->do_request($api_request_url, $param, 'GET', 'json');
}
}
else {
echo "All payee emails are already registered to Payquicker";
}
return $result_request ;
}
do_request函數將在Payquicker API中將json / xml值暫停為(GET / POST)
使用foreach:
function get_email_verification(){
$result_request = array();
$api_request_url = "http://api.payquicker.com/api/IsActiveAccount";
foreach ($this->get_payqucker_emails() as $email) {
$param = "email=".$email;
$result_request[] = $this->do_request($api_request_url, $param, 'GET', 'json');
}
if (empty($result_request)) {
echo "All payee emails are already registered to Payquicker";
}
return $result_request;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.