Home  • Programming • PHP

Problem: Find the factorial in PHP

Method 1: By Loop

function factorial($n){
  $factorial = 1;
  for ($i=$n; $i>=1; $i--)
  {
   $factorial = $factorial * $i;
   }
 return $factorial;
}

Method 2: By Recursive

function factorial($n){
    if (1<$n){ 
	return $n*factorial($n-1);        
    }else { 
        return 1; 
    }
}
$result=factorial(6); echo $result;

Comments 1


<?php
		$a =array("dhaka","comillah","nator","rajshahi");
		
		foreach ($a as $Glasses{
			echo $b."<br>";
		}
		echo "<br>";
		
		
		asort($a);
		
		foreach($a as $c){
		
		echo $c."<br>";
		}

	?>

Share

Copyright © 2024. Powered by Intellect Software Ltd