Help me in finding error in my code for LCS in PHP
function longestCommonSubsequence($text1, $text2) {
        $temp1 = str_split($text1);
        $count = 0;
        for ($i = 0; $i < count($temp1); $i++) {
            $temp2 = str_split($text2);
            $j = $i;
            $tempCount = 0; $tempArray = [];
            while ($j < count($temp1)) {
                while (($index = array_search($temp1[$j], $temp2)) !== false) {
                    $tempArray[$j.'--'.$index] = $temp2[$index];
                    for ($k = 0; $k <= $index; $k++) {
                        unset($temp2[$k]);
                    }
                    $tempCount++;
                    $j++;
                }
                $j++;
            }
            print_r([$i, $tempCount, $tempArray]);
            $count = max($tempCount, $count);
        }
        
        return $count;
    }
Comments (0)