0

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 ([email protected],[email protected],[email protected], [email protected], [email protected],[email protected]) the only valid and registered email are [email protected] and [email protected], but im only getting the [email protected] 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

10
  • Not a direct problem but the code would run sooooo smoother if you'd do $num = count($email). There is no need to call the function twice. Commented Sep 12, 2013 at 8:56
  • this only execute once $result_request = $this->do_request($api_request_url, $param, 'GET', 'json'); Commented Sep 12, 2013 at 9:01
  • @ArkNet How do you know code inside the loop executes only once? Commented Sep 12, 2013 at 9:03
  • @Konstantin becoz im only getting 1 return 1 email. Commented Sep 12, 2013 at 9:05
  • 1
    you get 1 return value you overwriting it try, $result_request[] Commented Sep 12, 2013 at 9:08

1 Answer 1

1

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;     
     }
Sign up to request clarification or add additional context in comments.

5 Comments

what difference will it make? (between for and foreach)
@cske Thank you im getting the two email.
Move $api_request_url = ... before foreach. Not clean!
@hallaji yes i move it above as that is constant var.
@itachi: array keys can be anything, php arrays naturally hashes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.