gmp_init
(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)
Create GMP number
Description
Creates a GMP number from an integer or string.
Parameters
numAn integer or a string. The string representation can be decimal, hexadecimal, octal, or binary.
baseThe base to use for converting a
stringrepresentation.An explicit base can be between
2and62. For bases up to36, case is ignored; upper-case and lower-case letters have the same value. For bases37to62, upper-case letter represent the values10to35and lower-case letter represent the values36to61.If
baseis0then the actual base is determined from the leading characters ofnum. If the first two characters are0xor0X, the string is interpreted as a hexadecimal integer. If the first two characters are0bor0B, the string is interpreted as a binary integer. If the first two characters are0oor0O, the string is interpreted as an octal integer. Moreover, if the first character is0the string is also interpreted as an octal integer. In all other cases, the string is interpreted as a decimal integer.
Return Values
Return
Changelog
| Version | Description |
|---|---|
| 8.1.0 | Support for explicit octal prefixes 0o and 0O has been added for num strings. Interpretation of such prefixes when base is 0 has also been added. |
Examples
Creating GMP number
<?php
$a = gmp_init(123456);
$b = gmp_init("0xFFFFDEBACDFEDF7200");
?>Notes
It is not necessary to call this function in order to use integers or strings in place of GMP numbers in GMP functions (such as with gmp_add()). Function arguments are automatically converted to GMP numbers, if such conversion is possible and needed, using the same rules as gmp_init().
See Also
GMP::__construct