PHP Syntax

PHP Tags

PHP code must be written inside <?php ... ?> tags:

Loading...
Output:

Everything inside the tags is interpreted by the PHP engine.

Semicolons

Each PHP statement ends with a semicolon:

Loading...
Output:

Case Sensitivity

Variable names are case-sensitive, but keywords like if, echo, and while are not:

$Name = "Alice";
echo $Name;  // works
echo $name;  // undefined

Comments

PHP supports single-line and multi-line comments:

// This is a single-line comment
# This is another single-line comment
/* 
   This is a 
   multi-line comment 
*/

Whitespace and Formatting

PHP ignores extra whitespace, but consistent indentation improves readability.

<?php
  $a = 10;
  $b = 20;
  if ($a < $b) {
    echo "A is less than B";
  }
?>

HTML + PHP Together

<html>
<body>

<?php
  echo "<h1>Hello from PHP!</h1>";
?>

</body>
</html>

You can switch between HTML and PHP seamlessly in one file.

Need Help?

Ask the AI if you need help understanding or want to dive deeper in any topic