PHP gmp_init() Function Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report The gmp_init() function is an inbuilt function in PHP that is used to create a GMP number from different data types, including strings, integers, or other GMP objects. It's commonly used when you want to start performing arithmetic operations on large numbers without losing precision. Syntax: gmp_init( int|string $num, int $base = 0 ): GMPParameters: This function accepts two parameters that are described below. $num: The number you want to initialize as a GMP object. It can be provided as a string, an integer, or another GMP object.$base: The base of the number representation. It can be specified as an integer from 2 to 62. If not provided or set to 0, the function will try to determine the base automatically based on the input string.Return Value: The gmp_init() function returns a GMP resource that represents the initialized number. Program 1: The following program demonstrates the gmp_init() function. PHP <?php $number = gmp_init("12345"); var_dump($number); ?> Output: object(GMP)#1 (1) { ["num"]=> string(5) "12345"}Program 2: The following program demonstrates the gmp_init() function. PHP <?php $hexNumber = "1A3B5"; $decimalNumber = 123456789; $gmpHex = gmp_init($hexNumber, 16); $gmpDecimal = gmp_init($decimalNumber); // Perform arithmetic operations on GMP numbers $sum = gmp_add($gmpHex, $gmpDecimal); $product = gmp_mul($gmpHex, $gmpDecimal); $sumAsString = gmp_strval($sum); $productAsString = gmp_strval($product); echo "Hex + Decimal = $sumAsString\n"; echo "Hex * Decimal = $productAsString\n"; ?> Output: Hex + Decimal = 123564234Hex * Decimal = 13264814694105Reference: https://www.php.net/manual/en/function.gmp-init.php Comment More infoAdvertise with us Next Article PHP gmp_init() Function N neeraj3304 Follow Improve Article Tags : PHP PHP-function PHP-gmp Similar Reads PHP isset() Function The isset() function in PHP checks whether a variable is declared and not NULL. It returns true if the variable exists and has a non-NULL value, and false otherwise, without modifying the variable. Syntaxbool isset( mixed $var [, mixed $... ] )Parameters: This function accept one or more parameter a 3 min read PHP linkinfo() Function The linkinfo() function is an inbuilt function in PHP that retrieves information related to the links. This function checks the link is pointed to by the path that exists. Syntax: linkinfo(string $path)Parameter: This function accepts one parameter that is described below: $path: Â This parameter spe 1 min read PHP | inet_pton() Function The inet_pton() function is an inbuilt function in PHP which converts a readable format IP address into a packed 32bit IPv4 or 128bit IPv6 address. Syntax: string inet_pton( string $ip_address ) Parameters: This function accepts single parameter as mentioned above and described below: $ip_address: I 1 min read PHP | inet_ntop() Function The inet_ntop() function is an inbuilt function in PHP which converts a 32bit IPv4 or 128bit IPv6 address into a readable format. Syntax: string inet_ntop( string $ip_address ) Parameter: This function accepts one parameter as mentioned above and described below: $ip_address: It is required paramete 1 min read PHP | ftp_login() function The ftp_login() function is an inbuilt function in PHP which is used to login to an established FTP connection. Syntax: ftp_login( $ftp_connection, $ftp_username, $ftp_userpass ); Parameter: This function accepts three parameters as mentioned above and described below: $ftp_connection: It is require 2 min read Like