PHP for calculating the factorial of a number without using loops


function factorial($n) {
  if ($n === 0) {
    return 1;
  } else {
    return $n * factorial($n - 1);
  }
}

This code snippet implements the factorial function using recursion, by defining a simple base case for when the input is 0 and a recursive case to compute the factorial of the input by multiplying it with the result of calling the function again with the input decreased by 1. This approach is concise and efficient for calculating factorials without using loops.