PHP Introduction · Lesson 6 of 7
PHP Syntax
Learn statement endings, blocks, and PHP tags.
Lesson
PHP statements normally end with a semicolon. Curly braces group statements into blocks, for example inside a function or conditional. Whitespace and indentation help readers understand the structure but do not replace correct syntax.
PHP keywords are generally case-insensitive, but variable names are case-sensitive. Use consistent formatting and descriptive names so mistakes are easier to spot.
If PHP reports a parse error, read the file name and line number, then check the nearby statement terminator, quote, parenthesis, and brace.
Further guidance
For every setup lesson, verify which PHP version and extensions are active in the same environment that runs the project. Keep a small reproducible script, use the command-line version output to diagnose configuration problems, and distinguish local development tools from production services.
Practice task: Create a fresh example for PHP Syntax. Predict the result before running it, then change one input and explain why the result changes. Test a normal case and one boundary or invalid case where it applies. Compare your output with the example and note one rule you would use in a real project.
Code examples
A PHP statement and block
PHP
$ready = true;
if ($ready) {
echo "Ready";
}
Expected output
Ready
Key points
- End ordinary PHP statements with a semicolon.
- Use braces to make blocks and indentation to make them readable.
- Variable names are case-sensitive.
Your learning progress
Finish this lesson
Optional practice
PHP playground
This site does not execute learner-provided PHP code. Connect a secured PHP sandbox service before enabling code execution.
Execution is disabled. No code is sent to a server.