Calculate quantity by integer

1

I have to insert a record in the database according to an integer. For example, 20, 21, 22, 23 ... 29 I get the first number (in case 2) and I enter 2 records. If it is 10, 11, 12, 13 ... 19 (in case 1) I enter 1 record. 0,1,2,3,4 ... 9 I enter none ...

I just need to know if it's from 0 to 9, 10 to 11, 20 to 22, and so on. According to which number I get the first number. The problem of doing for example with substr is if the number is 100 then it will "think" that it is values between 10 and 19.

    
asked by anonymous 15.01.2016 / 23:54

1 answer

6

Divide by 10, take the whole part, and use the result in your checks. For example:

$dezenas = floor($num / 10);
if ($dezenas == 1) {

} else if ($dezenas == 2) {

} // etc.
    
16.01.2016 / 00:17