DWPD-3.3: Write PHP Script user defines function.

user define function
Lab # 3

FUNCTIONS

3. Write PHP Script user defined function.

Lab-3-3-user-define-function.php

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php

function factorial( $n ) {

// Base case
if ( $n == 0 ) {
return 1;
}

// Recursion

$result = ( $n * factorial( $n-1 ) );
return $result;
}

echo "The factorial of 5 is: " . factorial( 5 );

?>




Output

user define function practical 3
User Define function in php here factorial number example by practical server



Happy Coding :)p

Leave a comment