Hello!

BrainTech - software solutions, web design and applications.

Contact

Module 2 – PHP Fundamentals Lesson

Variables

Naming and assigning values

Variables in PHP start with $ and carry a name that describes the content (e.g. $email, $ukupnaCena). Assignment uses the = operator. PHP is dynamically typed – the type is determined by the value, but from PHP 7.4+ you can use type hints in functions. Constants are defined with define() or const inside classes.

Naming rules

  • Letters, numbers, and _, must not start with a number.
  • Case-sensitive: $Ime and $ime are different.
  • Avoid reserved words (echo, class).
<?php
$cena = 1200;
$popust = 0.1;
$zaPlacanje = $cena * (1 - $popust);
define("PI", 3.14159);

Example variation

Extend the price and discount example: add a VAT rate, item quantity, and display the invoice line in an HTML table.

<?php
$cena = 2500;
$kolicina = 3;
$pdv = 0.20;
$ukupno = $cena * $kolicina * (1 + $pdv);
echo "Ukupno sa PDV: {$ukupno} RSD";
Design Wireframe
High Fidelity Design
Design development
Design development
Design development
Research development