How to print text diagonally from left to right recursively in PHP

1 Answer

0 votes
function printTextDiagonallyRecursivelyLTR($spaces, $text) {
    if (strlen($text) > 0) {
        echo $spaces . $text[0] . "\n";
        printTextDiagonallyRecursivelyLTR($spaces . " ", substr($text, 1));
    }
}

printTextDiagonallyRecursivelyLTR("", "HELLO WORLD");



/*
run:

H
 E
  L
   L
    O
      
      W
       O
        R
         L
          D

*/

 



answered Apr 8 by avibootz

Related questions

...