PHP CHAPTER 03

PHP Syntax

PHP syntax is the set of rules used to write valid PHP programs.

📘

What is it?

PHP syntax is the set of rules used to write valid PHP programs.

💡

Why do we use it?

Correct syntax allows the PHP interpreter to understand and execute your program.

⚙️

How does it work?

PHP reads statements inside PHP tags and executes them in order.

🧩

Syntax

PHP Syntax
<?php
$variable = value;
echo $variable;
?>
💻

Example

PHP Example
<?php

$name = "AIFA";
echo $name;

?>
🔍

Example Explained

$name creates a variable and stores AIFA. echo outputs its value.
🚀

More Examples

<?php $age = 20; $course = "PHP"; echo $age . " - " . $course; ?>

⚠️ Important Rules

PHP variable names start with $. Statements normally end with semicolons.

❌ Common Mistakes

Missing semicolon, unmatched quotes, incorrect variable names and missing PHP tags.

🌍 Real-World Use

Every PHP application depends on valid syntax.

📝 Practice Exercise

Create five PHP statements using variables and echo.

💻 Try It Yourself

Write and run this PHP lesson inside the AIFA Coding Lab.

Open Coding Lab →