Читать книгу PHP Programming for Beginners. Key Programming Concepts. How to use PHP with MySQL and Oracle databases (MySqli, PDO) - Sergey D Skudaev - Страница 4

Basic Operators

Оглавление

Any computer language uses operators to calculate or compare variables, most of which are self-explanatory. For example, PHP uses + (plus), – (minus), * (multiplication), / (division), % (modulo) and "=" the assignment operator.

Let’s discuss the modulo operator. The modulo operator is used in finding the resultant remainder after one number has been divided into another. The following are a couple of examples to help you better understand:

The first example is 15% 5 = 0. As you can see, 5 divides evenly into 15 with no remainder, so the result we get is 0. Now let’s use 10% 7 = 3 as our second example. Because 7 divides into 10 once and leaves a remainder of 3, our answer must be 3.

30% 6 = 0 (30 – 5 * 6 = 30 30 – 30 = 0)

30% 7 = 2 (30 – 4 * 7 = 30 – 28 = 2)

30% 8 = 6 (30 – 3 * 8 = 30 – 24 = 6)

PHP Programming for Beginners. Key Programming Concepts. How to use PHP with MySQL and Oracle databases (MySqli, PDO)

Подняться наверх