简体   繁体   中英

function inside FOR LOOP execute only once

i have an array of email add that needs to be verified. When I call the function during iteration, loop stops after first iteration and does not proceed over entire array. and the return value.

$num contains 6, and $email compose of (1st@yahoo.com,2nd@yahoo.com,3rd@yahoo.com, 4th@yahoo.com, 5th@yahoo.com,6th@yahoo.com) the only valid and registered email are 1st@yahoo.com and 6th@yahoo.com, but im only getting the 6th@yahoo.com which is the last.

  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 ; 

    }

The do_request function will pause a json/xml value to (GET/POST) in Payquicker APIs

Use 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;     
     }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM