PHP Numbers

PHP supports two types of numbers: integers and floats.

Example of PHP Integers

<?php
$integer1 = 10;
$integer2 = -5;
$integer3 = 0;

echo gettype($integer1) . "\n";
// Outputs: integer
echo gettype($integer2) . "\n";
// Outputs: integer
echo gettype($integer3) . "\n";
// Outputs: integer
?>

Output:

integer
integer
integer

Explanation: This example demonstrates the use of integers in PHP. The gettype() function is used to determine the data type of each variable.

Example of PHP Floats

<?php
$float1 = 10.5;
$float2 = -3.14;
$float3 = 0.0;

echo gettype($float1) . "\n";
// Outputs: double
echo gettype($float2) . "\n";
// Outputs: double
echo gettype($float3) . "\n";
// Outputs: double
?>

Output:

double
double
double

Explanation: This example demonstrates the use of floats in PHP. The gettype() function is used to determine the data type of each variable.

Example of PHP Number Functions

<?php
$number = 10;

echo is_int($number) . "\n";
// Outputs: 1
echo is_float($number) . "\n";
// Outputs: 
echo is_numeric($number) . "\n";
// Outputs: 1
?>

Output:

1

1

Explanation: This example demonstrates the use of number functions in PHP, including is_int(), is_float(), and is_numeric().