I want to save a 11 digit number inside a variable. How can I do this in PHP?
PHP Integers An integer data type is a non-decimal number between -2147483648 and 2147483647 in 32 bit systems, and between -9223372036854775808 and 9223372036854775807 in 64 bit systems.
Zend\Math\BigInteger\BigInteger offers a class to manage arbitrary length integers. PHP supports integer numbers with a maximum value of PHP_INT_MAX , a value defined by your processor architecture and available memory.
The major difference between an Integer and an int is that Integer is a wrapper class whereas int is a primitive data type. An int is a data type that stores 32-bit signed two's complement integer whereas an Integer is a class that wraps a primitive type int in an object.
PHP int size is platform-dependent, and it seems to be 8 bytes on our 64-bit boxes. Yes, the very same ones where C/C++ int is 4 bytes, you know.
The 64-bit version of PHP uses 64-bit integers natively, so that's plenty of bits for an 11-digit number. That said, if you need larger integers, I would use the BC Math extension.
The GMP library is also worth looking at.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With