So, I've written a code to find all possible paths for M x N matrix
function printRobotPaths($path,$m,$n,$x,$y) {
if (($x == $m-1) && ($y == $n-1)) {
return $path;
}
if ($x == $m-1) {
return printRobotPaths($path.'D',$m,$n,$x,$y+1);
}
if ($y == $n-1) {
return printRobotPaths($path.'R',$m,$n,$x+1,$y);
}
printRobotPaths($path.'D',$m,$n,$x,$y+1);
printRobotPaths($path.'R',$m,$n,$x+1,$y);
}
$m = 3;
$n = 3;
$x = 0;
$y = 0;
$data = array(
array(1,2,3),
array(4,5,6),
array(7,8,9)
);
$path = printRobotPaths('',$m,$n,0,0);
var_dump($path);
but the problem is when I'm returning $path then it var_dump() result is NULL but for same if I just print $path inside the function it will print correct answer
I wanted to return all possible 6 ways from it.