PHP

What is recursion in PHP

Kartic1 min read

Recursion is a programming solution in which a function calls itself. It is used to solve a variety of problems, all of which have in common a structure that contains repetition. Recursion can be useful when solving problems related to HTML and other repetitive structures such as JSON and XML.

function calcFactorial($num)

{

    if ($num <= 1) {

        return 1;

    } else {

        return ($num * calcFactorial($num-1));

    }

} 

echo calcFactorial(5);

Share this articleLinkedIn X

Discussion (0)

Sign in to join the discussion.

Delete this comment?

This will also remove its replies.

Keep exploring

PHP1 min read

PHP and Mysql environment with Docker

Create a Dockerfile in your PHP project FROM php:8.2-cli COPY . /usr/src/myapp WORKDIR /usr/src/myapp CMD [ "php", "./your-script.php" ] Then, run the commands to build and run the...

Kartic · Nov 20, 2024
PHP1 min read

What is the difference between PHP's get & post method

​​​​​​​Get MethodGET requests can be cachedGET requests remain in the browser historyGET requests can be bookmarkedGET requests should never be used when dealing with sensitive dat...

Kartic · Oct 27, 2019
PHP1 min read

What is PHP?

The PHP Hypertext Preprocessor (PHP) is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for develop...

Kartic · Oct 22, 2019

Follow the engineering notes.

Subscribe for technical articles from iTechOrbit.