You can do it on that way round($number / 5, 1) * 5
the second parameter in the round()
is the precision.
Example with $number
equal to 4.6, 4.8 and 4.75
>>> round(4.6 / 5, 1) * 5;=> 4.5>>> round(4.8 / 5, 1) * 5;=> 5.0>>> round(4.75 / 5, 1) * 5;=> 5.0
If you want you can round()
down too like round($number, 1, PHP_ROUND_HALF_DOWN)
check the documentation for more information https://www.php.net/manual/en/function.round.php