gpt4 book ai didi

php - 对用户定义函数中的 return 语句感到困惑

转载 作者:可可西里 更新时间:2023-10-31 22:07:40 25 4
gpt4 key购买 nike

我对返回声明几乎没有疑问。

a) 是否必须在用户定义的函数中定义返回语句?

b) 如果我只定义一个没有任何参数的 return 语句,它仍然有效吗?它会返回空值吗?

c) 下面的函数有效吗?

function admin_credential($password = 0, $email = 0) {
if( $password != 0) {
$password = sha1($password);
$query = "UPDATE admins SET password = '$password'";
$result = mysql_query($query);
}
if( $email != 0) {
$query = "UPDATE admins SET email = '$email'";
$result = mysql_query($query);
}
return;
}

最佳答案

a) is it compulsory to define a return statement in a user defined function.?

没有。

b) is it still valid if i just define a return statement without any parameter? will it return the null value?

是的。

c) is the following function valid?

是的,但是 $result 会丢失,因为您没有返回它。 return 并不是真正必要的。

关于php - 对用户定义函数中的 return 语句感到困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3701938/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com