PHP 函数的返回值
下面的代码有什么问题?希望你明白我想做什么。我对函数不是很熟悉。
function test ($variable) {
$one = 3;
if ($variable == 10) {
$one = "2";
}
return $one;
}
foreach ($array as $arraypart) {
$part = explode(',',$arraypart);
test($part[0]);
echo $one;
}
what is wrong with the following code? Hope you understand what I'm trying to do. I'm not very familiar with functions.
function test ($variable) {
$one = 3;
if ($variable == 10) {
$one = "2";
}
return $one;
}
foreach ($array as $arraypart) {
$part = explode(',',$arraypart);
test($part[0]);
echo $one;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将函数的结果分配给变量:
You need to assign the result of function to a variable:
这里发生了什么,你的函数被调用,但没有变量来捕获 test() 返回的内容......
你需要捕获 temp func 返回的值,如下所示
$val = temp($part[0]);
或者
你可以直接写 echo temp($part[0]);
here what happens, your function is being called but no variable is there to catch what test() is returning....
you need catch value which is returned by temp func like this
$val = temp($part[0]);
or
you can write direct echo temp($part[0]);