What is gmp_init in PHP?

gmp_init is a function in PHP that creates a GMP number.


GMP stands for GNU Multiple Precision


Syntax


gmp_init(int|string $num, int $base = 0): GMP

Parameters

  • num: This can either be of the string type or the int type.

If num is of the string type, it can be a decimal, hexadecimal, or octal number.


  • base: An optional parameter. The base can have values from 2 to 36. The value by default is zero.

Properties

If the value of base is zero, the leading characters determine the actual base.

  • If the first two characters are 0x/0X, then hexadecimal is considered.

  • If the first two characters are 0b/0B, the binary is considered.

  • If the first character is 0 then octal is considered.

  • If these conditions are not satisfied, the decimal is considered.

Return value

The function returns a GMP number.

Code

<?php
$val1 = gmp_init(12);
echo $val1."\n";
$val2 = gmp_init(0101, 2);
echo $val2."\n";
?>

Output


12
5

Free Resources