0

我有一系列需要验证的电子邮件添加。当我在迭代期间调用该函数时,循环在第一次迭代后停止并且不会在整个数组上进行。和返回值。

$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 函数将暂停一个 json/xml 值到 Payquicker API 中的 (GET/POST)

4

1 回答 1

1

使用 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;     
     }
于 2013-09-12T09:07:13.707 回答