PHP Math
PHP provides arithmetic operators and mathematical functions.
What is it?
PHP provides arithmetic operators and mathematical functions.
Why do we use it?
Math functions are useful for calculations, rounding and numeric processing.
How does it work?
PHP evaluates arithmetic expressions and functions such as round, ceil, floor, abs, pow and sqrt.
Syntax
round($value); ceil($value); floor($value);
Example
<?php $price = 99.75; echo round($price) . "<br>"; echo ceil($price) . "<br>"; echo floor($price); ?>
Example Explained
More Examples
<?php echo abs(-25) . "<br>"; echo pow(2, 3) . "<br>"; echo sqrt(64); ?>
⚠️ Important Rules
Choose the mathematical function according to the required business rule.
❌ Common Mistakes
Using the wrong rounding function.
🌍 Real-World Use
Used in billing, discounts, marks, statistics and financial calculations.
📝 Practice Exercise
Create a discount calculator using PHP Math functions.
💻 Try It Yourself
Write and run this PHP lesson inside the AIFA Coding Lab.