user3746250
user3746250

Reputation: 27

php exit while loop inside a function

I have a function that return a value by checking an exiting details in database mysql inside the function I have a while loop by an array from sql query. I want to break the while loop if its find a mach how should I do it ?

this is my code:

     function chklogin()
 {
                $query = mysql_query("SELECT * FROM sg_loginlastauthentication WHERE uid = '$autoid' ");
                $checkLogin = mysql_num_rows($query);
                if ($checkLogin==0)
                {
                    return "FALSE"; // auth fail                    
                }               
                elseif ($checkLogin>1) 
                {
                    while($row = mysqli_fetch_array($query))
                    {
                                $userip = $row['uipadd'];
                                $userra = $row['randomnu'];
                                $userid = $row['uid'];
                                $cookieipadd = md5(md5(getclientip()));
                                $authdb = md5($userid + $userip + $userra);
                                $authusco = md5($userid + $cookieipadd + $userra);
                                if ($authdb==$authusco) //ok
                                    {
                                        return "TRUE";
                                    }                  
                    }

                }  
}

does the "return true" is breaking the loop or I need to place a "break;" before/after the "return" ?

Upvotes: 0

Views: 3004

Answers (1)

idmean
idmean

Reputation: 14895

Yes, it is breaking the loop

No, you don't need to put a break after return

If called from within a function, the return statement immediately ends execution of the current function.

From PHP: return

Upvotes: 3

Related Questions