PHP code is written between <?php and ?>. In files that contain only PHP, leave out the closing ?>.
Every statement ends with a semicolon ;.
Keywords (echo, if, function) are not case-sensitive.
Variable names are case-sensitive: $name and $Name are different.
echo and print output text.
PHP Comments
// single line, # single line, /* multi-line */
💡 Key Takeaways: PHP Syntax
Mastering PHP Syntax helps you write clean and reliable PHP code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
PHP Syntax Code Example
PHP
<?php
// A single-line comment
$color = "teal";
echo "My car is " . $color . "<br>";
ECHO "Keywords are case-insensitive<br>";
print "print also works";
Output
My car is teal
Keywords are case-insensitive
print also works
Run this example on your own computer. The "Get Started" lesson shows how to set it up.