PHP | gmp_intval() Function
The gmp_intval() is an inbuilt function in PHP which converts a GMP number to an integer. Here GMP refers to GNU Multiple Precision which is for large numbers.
Syntax:
int gmp_intval ( $num )
Parameters: The function accepts a single parameter $num which is a GMP number and returns its integer value. This parameter can be a GMP object in PHP version 5.6 and later, or we are also allowed to pass a numeric string provided that it is possible to convert that string to a number.
Return Value: The function returns integer value of the given GMP number $num
Examples:
Input : $num = "2147483647" Output : 2147483647 Input : $num = "12" Output : 12
Note: If a numeric string is passed as an integer, it returns the same integer (except above PHP integer limit). But if a GMP number is passed, it returns the integer value of a GMP number.
Below programs illustrate the use of gmp_intval() function:
Program 1: The program below demonstrates the working of gmp_intval() function when numeric string is passed as an argument.
<?php // PHP program to demonstrate the gmp_intval() // function when argument is passed $x = gmp_intval("2147") . "\n"; // prints integer value of a gmp number // it returns the same numeric string in integer form echo gmp_strval($x) . "\n"; ?> |
Output:
2147
Program 2: The program below demonstrates the working of gmp_intval() when GMP number is passed as an argument.
<?php // PHP program to demonstrate the gmp_intval() function // when GMP number is passed as an argument // arguments as GMP numbers $num = gmp_init("1111", 2); // num initialisation = 12 // integer vaulue of GMP number 12 is 12 $x = gmp_intval($num); // prints the integer value of a gmp number // gmp_strval converts GMP number to string // representation in given base(default 10). echo gmp_strval($x) . "\n"; ?> |
Output:
7
Reference:
http://php.net/manual/en/function.gmp-intval.php
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to get the function name from within that function using JavaScript ?
- PHP | tan( ) Function
- PHP | Ds\Set contains() Function
- PHP | end() Function
- PHP | pos() Function
- PHP | key() Function
- PHP | Ds\Map put() Function
- p5.js | value() Function
- p5.js | max() function
- PHP | Ds\Map xor() Function
- D3.js | d3.rgb() Function
- p5.js | pow() function
- p5.js | day() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

