PHP Basic Syntax

PHP code starts with <?php and ends with ?> tag. PHP also has a short opening tag <? but is only available if the short_open_tag is enabled in the php.ini file.

Unlike JavaScript, PHP is case insensitive. This means the FUNCTION and function is the same. See the example below:

<?php

    FUNCTION sayHi() {
	  RETURN 'hi';
    }
    echo sayHi(); // prints "hi";
    Echo sayHi(); // prints "hi";
    ECHO sayHi(); // prints "hi";

?>

  Do It Yourself

PHP Comments

A comment is a code that is skipped by the compiler when PHP is executed. It is used to give descriptions or notes about your code, this could be to remind yourself of a TODO or inform other co-developers about important actions.

PHP supports single-line // and multi-line /**/ comments.

PHP Single-line Comment

<?php

   // Hi, I am a single-line comment.

   # I can also be written like this.

?>

PHP Multi-line Comment

<?php

    /*
        Hi, I am a multi-line comment.
    */

?>

 

What You Should Know at the End of This Lesson

  • You should know about PHP's opening and closing tags.
  • PHP comments.
  • Types of PHP comments (single-line and multi-line comments).