[英]Converting javascript code to PHP : Determining what return (1) means in javascript
I have this code in JS 我在JS中有这个代码
function calc(bth){
var y,cont;
y=(Math.abs(1965-bth))/4;
y=y-Math.floor(y);
if(y){
cont=calc(bth+1);
return(cont+1);
} else {
return(1); // <-- what is the meaning of this line?
}
}
I converted it to PHP as 我将其转换为PHP
function calc($yr)
{
$y = (abs(1965 - $yr))/4;
$y = $y- floor($y);
if($y)
{
$cont= calc($yr+1);
return ($cont + 1);
}
else
{
return (1); //<--- stuck here
}
}
I realized that return (1)
in javascript is not the same as return (1)
in PHP. 我意识到return (1)
在JavaScript是不一样的return (1)
在PHP。 I went over some SO topics regarding this topic but didn't find a suitable match for my kind of scenario. 我讨论了关于这个主题的一些SO主题,但没有找到适合我的场景的匹配。
In my context, what would return (1)
return in javascript? 在我的上下文中,什么会return (1)
返回javascript? I would also appreciate if the values of return (0)
and return (-1)
in javascript are made known to me so that I get acquainted with this information. 如果我知道javascript中的return (0)
和return (-1)
的值,以便我熟悉这些信息,我将不胜感激。
Don't overcomplicate the problem. 不要过分复杂化问题。 It will simply return 1
, as if you write return 1
. 它只会返回1
,就像你写return 1
。
Most probably brackets were left from copying of return(cont+1)
. 最常见的括号是复制return(cont+1)
。
return
is not a function, ()
is not necessary for return statement. return
不是函数,return语句不需要()
。
Just do with return cont + 1;
只需return cont + 1;
and return 1;
并return 1;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.