• PHP Video Tutorials

PHP - gmp_​nextprime() Function



Definition and Usage

The gmp_​nextprime() function helps to find the next prime number.

Description

The gmp_​nextprime() function returns the next prime number that is greater than the given GMP number.

Syntax

gmp_nextprime ( int $a ) : GMP

Parameters

Sr.No Parameter & Description
1

a

It can a GMP resource number , a gmp object or a numeric string.

Return Values

PHP gmp_​nextprime() function returns a GMP number.The number returned is a perfect prime number and greater than given GMP number.

PHP Version

This function will work from PHP Version greater than 5.2.0.

Example 1

Working of gmp_​nextprime() −

<?php
   $num = gmp_nextprime("2299897");	
   echo "The next prime number after 2299897 is :".$num; 
?>

This will produce following result −

The next prime number after 2299897 is :2299901

Example 2

Working of gmp_​nextprime() −

<?php
   $num = gmp_nextprime("50");	
   echo "The next prime number after 50 is :".$num; 
?>

This will produce following result −

The next prime number after 50 is :53
php_function_reference.htm
Advertisements