Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
gmp_init
communitycreator

What is gmp_init in PHP?

Hammad Nasir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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

RELATED TAGS

php
gmp_init
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring