1

hi guys i am Currently Confused why do i get this error about missing argument when i compile the code it gives me this error Warning: Missing argument 5 for print_LCS(), here is my code:

this is the function

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);
}

and this is the function call:

list($final)=print_LCS($var2,$first,$var3,$var4,$var5);

hoping for your quick response guys. thank you So much.

1 Answer 1

5

The problem is the nested calls to the same function ( presumably for recursion ) as it only has 4 values passed to it.

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);
}

Not knowing what the funtion is doing it is hard to say whether this might work or cause more issues but you could supply the fifth parameter with a default value in the initial declaration, like:

function print_LCS($b,$x,$i,$j,$k=false){/* rest of function */}

That way it would happily continue at the points it failed - though what the 5th parameter brings to the table is unknown.

Sign up to request clarification or add additional context in comments.

3 Comments

thank you very much the error was solved but the function is still not working properly i want to use the $k variable to function as a counter to the index of the array $fLCS to save the value coming from $x[$i-1] and return it but the problem is that the counter wont move it only returns the value in the [0] index. how could i fix that. thanks for the help
I don't know as I don't understand what the function is doing, no idea what values are being passed in initially nor what the expected output is.
okay sir thank you for the time in helping me, at least i know the reason for missing arguments. by the way the function is printing the longest common sub-sequence of the given two sequences of words.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.