A function is a reusable block of code — write it once, call it from many places. Put repetitive logic like calculations, formatting, validation, or database helpers into functions, and your code stays clean and easy to maintain.
php
<?php
function calculateDiscountPrice($price, $discountPercent) {
$discountAmount = $price * ($discountPercent / 100);
return $price - $discountAmount;
}
echo "Final price: " . calculateDiscountPrice(20000, 15) . " MMK";
?>You should see
Final price: 17000 MMK