What is the gmp_nextprime() function in PHP?

The gmp_nextprime() function in PHP is used to return the next prime number, which is greater than the argument passed.

Syntax


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

Parameters

The function takes in one parameter, num.


num can be a numeric string, GMP object, or of type int.


Return value

The function returns the next prime number which is a greater num. The value returned is type GMPGNU Multiple Precision Arithmetic Library number.

Code

<?php
$primeNum1 = gmp_nextprime(12);
$primeNum2 = gmp_nextprime(16);
echo gmp_strval($primeNum1) . "\n";
echo gmp_strval($primeNum2) . "\n";
?>

Output


13
17

Free Resources