How to get multiple of some PHP value?

Asked

Viewed 946 times

10

I need to do a search in the database and according to the value found within a range of values must return a specific value.

For example: if you find the values 1 to 4, you must return 1, finding 5 to 8, return 2.

The multiple of a given value is required.

1 answer

11


What you need is the function Ceil(), which rounds up values.

So you can use:

$valorRetornado = ceil($seuValor / 4);

For example:

echo ceil(1 / 4);     // dá 1
echo ceil(4 / 4);     // dá 1
echo ceil(5 / 4);     // dá 2
echo ceil(8 / 4);     // dá 2
echo ceil(54654 / 4); // dá 13664

Browser other questions tagged

You are not signed in. Login or sign up in order to post.