0
0
PHPprogramming~5 mins

Integer type and behavior in PHP

Choose your learning style9 modes available
Introduction

Integers are whole numbers without decimals. They are used to count or measure things exactly.

Counting items like apples or books.
Storing age or number of people.
Doing math with whole numbers like addition or subtraction.
Using loops that repeat a set number of times.
Representing states or options with numbers.
Syntax
PHP
<?php
$number = 123;
$negative = -456;
$zero = 0;
?>

Integers can be positive, negative, or zero.

PHP automatically treats numbers without decimals as integers.

Examples
Examples of positive, negative, and zero integers.
PHP
<?php
$age = 30;
$score = -15;
$zero = 0;
?>
Integers have limits depending on the system (usually 32 or 64 bits).
PHP
<?php
$bigNumber = 2147483647; // largest 32-bit integer
$smallNumber = -2147483648; // smallest 32-bit integer
?>
You can do math with integers like addition and subtraction.
PHP
<?php
$sum = 10 + 5; // 15
$diff = 10 - 3; // 7
?>
Sample Program

This program shows how to use integers to count fruits, show negative numbers, and zero.

PHP
<?php
$apples = 5;
$oranges = 3;
$total = $apples + $oranges;
echo "Total fruits: $total\n";

$negativeNumber = -10;
echo "Negative number: $negativeNumber\n";

$zero = 0;
echo "Zero value: $zero\n";
?>
OutputSuccess
Important Notes

PHP integers can be 32-bit or 64-bit depending on your system.

If a number is too big for an integer, PHP converts it to a float automatically.

Use var_dump() to check the type of a variable.

Summary

Integers are whole numbers without decimals.

They can be positive, negative, or zero.

Use integers when you need exact whole numbers for counting or math.