What is gmp_fact in PHP?

gmp_fact is a function in PHP that calculates the factorial of the argument passed.

Syntax

gmp_fact(GMP|int|string $num): GMP

Parameters

The function takes in one parameter, num.

num can be a numeric string, GMPGNU Multiple Precision Arithmetic Library object, or an int type value.

Return value

The function returns the factorial of num. The value returned is a GMP type number.

Code

<?php
$val1 = gmp_fact(4);
echo gmp_strval($fact1) . "\n";
?>

Expected output

24
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources