1 php
嗨伙计们我目前很困惑为什么我在编译代码时得到关于缺少参数的错误它给了我这个错误警告:缺少参数5 for print_LCS(),这是我的代码:
这是功能
function print_LCS($b,$x,$i,$j,$k){
$fLCS=array();
if ($i==0||$j==0)
{
return 0;
}
if ($b[$i][$j]=='c')
{
print_LCS($b,$x,$i-1,$j-1);
$fLCS[$k] = $x[$i-1]." ";
$k++;
}
elseif ($b[$i][$j]=='u')
{
print_LCS($b,$x,$i-1,$j);
}
else
{
print_LCS($b,$x,$i,$j-1);
}
return array($fLCS);
}
Run Code Online (Sandbox Code Playgroud)
这是函数调用:
list($final)=print_LCS($var2,$first,$var3,$var4,$var5);
Run Code Online (Sandbox Code Playgroud)
希望你快速反应的人.非常感谢.
问题是对同一函数的嵌套调用(可能是递归),因为它只传递了4个值.
function print_LCS($b,$x,$i,$j,$k){
$fLCS=array();
if ($i==0||$j==0) {
return 0;
}
if ($b[$i][$j]=='c'){
print_LCS($b,$x,$i-1,$j-1, $XXXXX );/* you need another parameter here or a default value */
$fLCS[$k] = $x[$i-1]." ";
$k++;
} elseif ($b[$i][$j]=='u') {
print_LCS($b,$x,$i-1,$j,$XXXXX);/* you need another parameter here or a default value */
} else {
print_LCS($b,$x,$i,$j-1,$XXXXX);/* you need another parameter here or a default value */
}
return array($fLCS);
}
Run Code Online (Sandbox Code Playgroud)
不知道功能是什么,很难说这可能是否有效或导致更多问题,但您可以在初始声明中提供第五个参数和默认值,例如:
function print_LCS($b,$x,$i,$j,$k=false){/* rest of function */}
Run Code Online (Sandbox Code Playgroud)
这样它就会很高兴地继续它失败的点 - 尽管第五个参数带来的是未知的.