【发布时间】:2015-07-28 11:20:48
【问题描述】:
也许我的问题有点初级或愚蠢,但我需要验证这一点。
我有一个 php 函数“functionA”,它在 for 循环中被重复调用:
...
for($j=0; $j<$n_samples;$j++) {
if($type=='triband') {
functionA($arg1,$arg2);
}
}
...
和我的函数A:
...
functionA($arg1,$arg2) {
$wide_avg_txon = substr($bit_sequence,0,1);
if($wide_avg_txon==0)
{
echo " ---> is OFF...<br />";
}
else
{
echo " ---> is ON...<br />";
// if is ON then skip execution of code inside the function
return;
}
// DO SOME STUFF!
}
...
所以我不想执行 functionA 中的其余代码 if "$wide_avg_txon==1" 我只想继续执行 for 循环以进行下一次迭代!
上面的代码可以工作吗? 'return' 和 'return false' 之间有什么区别? 'return false' 是否也会起作用:
...
if($wide_avg_txon==0)
{
echo " ---> is OFF...<br />";
}
else
{
echo " ---> is ON...<br />";
// if is ON then skip execution of code inside the function
return false;
}
谢谢!
【问题讨论】:
-
两者都可以。如果你想以某种方式依赖它,你可以返回一些东西,例如if (functionA($arg1,$arg2 ==
)) {} -
如果您有任何需要,请发送至
return trueforon,因为true == 1。
标签: php if-statement return