php会像break一样退出吗?

时间:2011-04-04 03:10:46

标签: php

我正在看这个函数并注意到一些返回....执行php返回离开函数还是继续向下直到底部

function confirmUser($username, $password) {
    global $conn; /* Add slashes if necessary (for query) */
    if (!get_magic_quotes_gpc()) {
        $username = addslashes($username);
    }

    /* Verify that user is in database */
    $q = "select password from users where username = '$username'";
    $result = mysql_query($q, $conn);
    if (!$result || (mysql_numrows($result) < 1)) {
        return 1; //Indicates username failure
    }

    /* Retrieve password from result, strip slashes */
    $dbarray = mysql_fetch_array($result);
    $dbarray['password'] = stripslashes($dbarray['password']);
    $password = stripslashes($password);

    /* Validate that password is correct */
    if ($password == $dbarray['password']) {
        return 0; //Success! Username and password confirmed
    } else {
        return 2; //Indicates password failure
    }
}

2 个答案:

答案 0 :(得分:4)

它会立即将函数留在它所调用的位置。

答案 1 :(得分:4)

从函数返回。查看文档 - http://php.net/return