What is floor() in PHP?

The floor() function in PHP returns the next largest integer less than or equal to a number.

Figure 1 below shows the mathematical representation of the floor() function.

Figure 1: Mathematical representation of floor() function

Syntax


float floor(number)

Parameter

This function requires a number to round down as a parameter.

Return value

The floor() function returns the next largest integer less than or equal to the number set as a parameter.

Code

<?php
#Positive number
echo("floor(10): ");
echo (floor(10));
echo("\n");
echo("floor(5.3): ");
echo (floor(5.3));
?>
<?php
#Negative number
echo("floor(-10): ");
echo (floor(-10));
echo("\n");
echo("floor(-5.3): ");
echo (floor(-5.3));
?>

Free Resources