Thuta Learning
IntermediateProgrammingbeginner

Functions

Relax. We'll talk through this in plain words — no textbook voice.

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

Easy traps

  • If a function only echoes instead of returning a value, you'll have a hard time reusing that result in further calculations.
Functions | Thuta Learning