PHP CHAPTER 11

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

PHP Syntax
round($value);
ceil($value);
floor($value);
💻

Example

PHP Example
<?php

$price = 99.75;

echo round($price) . "<br>";
echo ceil($price) . "<br>";
echo floor($price);

?>
🔍

Example Explained

round rounds normally, ceil rounds upward and floor rounds downward.
🚀

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.

Open Coding Lab →