What is PHP floor() function?

The floor() function rounds a number down to the next lower whole number. It always returns a float.

<?php
echo floor(7.8) . "<br>";
echo floor(-3.2) . "<br>";
var_dump(floor(5.9));
?>

Output:

Tutorials Class - Output Window

7
-4
float(5)

Notice that floor(-3.2) is -4, because -4 is lower than -3.2. The related functions are ceil() (round up) and round() (round to the nearest). Use intdiv() for whole number division.


Learn more about the similar topics:
Tutorials
PHP Functions
Exercises & Assignments
Factorial program in PHP using recursive function
Write a PHP program to calculate area of rectangle
Interview Questions & Answers
What is PHP Function?
What is PHP floor() function?
How to count the number of parameters passed in a PHP function?
How can you pass a variable by reference in PHP?