Google News
logo
PHP Program to integer
In PHP, an integer is a whole number without a decimal point. You can use integers to represent things like counts, scores, and IDs.

Here's an example of an integer in PHP :
Program :
<?php
$score = 42;
echo "Your score is $score";
?>

In this example, the variable `$score` is assigned the value `42`. When the code is executed.

Output :
Your score is 42
You can perform arithmetic operations on integers in PHP :
Program :
<?php
$x = 10;
$y = 5;
$sum = $x + $y;
$diff = $x - $y;
$product = $x * $y;
$quotient = $x / $y;
$remainder = $x % $y;

echo "Sum: $sum\n";
echo "Difference: $diff\n";
echo "Product: $product\n";
echo "Quotient: $quotient\n";
echo "Remainder: $remainder\n";
?>

In this example, we declare two integer variables `$x` and `$y`, and then perform arithmetic operations on them.

Output :
Sum: 15
Difference: 5
Product: 50
Quotient: 2
Remainder: 0
You can also use comparison operators to compare integers :
<?php
$x = 10;
$y = 5;

if ($x > $y) {
    echo "$x is greater than $y";
} elseif ($x < $y) {
    echo "$x is less than $y";
} else {
    echo "$x is equal to $y";
}
?>​

In this example, we use the comparison operators `>` and `<` to compare the values of `$x` and `$y`.

10 is greater than 5