Php, How To Convert A String Into Number In Php

Summary: in this tutorial, you’ll learn about the PHP int type that represents integers in PHP.

Bạn đang xem: Php, how to convert a string into number in php

Introduction to lớn the PHP int type

Integers are whole numbers such as -3, -2, -1, 0, 1, 2, 3… PHP uses the int type to lớn represent the integers.

The range of integers depends on the platform where PHP runs. Typically, integers has a range from -2,147,438,648 khổng lồ 2,147,483,647. It’s equivalent to 32 bits signed.

To get the size of the integer, you use the PHP_INT_SIZE constant. Also, you use the PHP_INT_MIN & PHP_INT_MAX constants khổng lồ get the minimum & maximum integer values.

Xem thêm: Sửa Lỗi Bàn Phím Gta 5, Grand Theft Auto V Và Cách Khắc Phục

PHP represents integer literals in decimal, octal, binary, và hexadecimal formats.

Decimal numbers

PHP uses a sequence of digits without leading zeros to lớn represent decimal values. The sequence may begin with a plus or minus sign. If it has no sign, then the integer is positive. For example:

From PHP 7.4, you can use the underscores (_) to lớn group digits in an integer lớn make it easier to read. For example, instead of using the following number:

you can use the underscores (_) to lớn group digits lượt thích this:


Octal numbers

Octal numbers consist of a leading zero & a sequence of digits from 0 khổng lồ 7. Like decimal numbers, the octal numbers can have a plus (+) or minus (-) sign. For example:

+010 // decimal 8
Code language: JavaScript (javascript)

Hexadecimal numbers

Hexadecimal numbers consist of a leading 0x và a sequence of digits (0-9) or letters (A-F). The letters can be lowercase or uppercase. By convention, letters are written in uppercase.

Similar to decimal numbers, hexadecimal numbers can include a sign, either plus (+) or minus(-). For example:

0x10 // decimal 160xFF // decimal 255
Code language: JSON / JSON with Comments (json)

Binary numbers

Binary numbers begin with 0b are followed by a sequence of digits 0 & 1. The binary numbers can include a sign. For example:

0b10 // decimal 2
Code language: JavaScript (javascript)

The is_int() function

The is_int() built-in function returns true if a value (or a variable) is an integer. Otherwise, it returns false. For example:

$amount = 100;echo is_int($amount);
Code language: PHP (php)Output:



Integers are whole numbers such as -1, 0, 1, 2…Use the PHP_INT_SIZE constant to get the size of the integerUse the PHP_INT_MIN & PHP_INT_MAX constants to lớn get the minimum & maximum integer values.Literal integers can be in decimal, octal, hexadecimal, & binary forms.Use the is_int() function returns true if a value (or variable) is an integer.
Did you find this tutorial useful?
Yes No

PHP Boolean
Up Next
PHP float

search for:

Getting Started

PHP Fundamentals

Data Types


Control Flow



Sorting Arrays

Advanced Functions

Advanced Array Operations


PHP Login

File I/O

String Opearations

About helps you learn PHP programming from scratch.

Recent PHP Tutorials

Site Links