PHP includes math functions like abs(), round(), ceil(), floor(), and rand(). Use operators like + - * / for basic arithmetic. These are useful for calculations in shopping carts, scores, and financial reports.
Math Functions
abs(-5); // 5
ceil(4.1); // 5 (round up)
floor(4.9); // 4 (round down)
round(4.5); // 5
round(3.14159, 2);// 3.14
sqrt(16); // 4
pow(2, 8); // 256
max(1, 5, 3); // 5
min(1, 5, 3); // 1
rand(1, 100); // random between 1-100
mt_rand(1, 100); // faster random
number_format(1234567.891, 2, ".", ","); // 1,234,567.89
intdiv(7, 2); // 3 (integer division)
fmod(7, 2); // 1.0 (float modulo)
log(M_E); // 1 (natural log)
pi(); // 3.14159...
PHP_INT_MAX; // 9223372036854775807