Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

PHP Comments

PHP supports various methods of commenting:

Example

Syntax for comments in PHP code:

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

Single Line Comments

Single-line comments begin with //.

Any text following // until the end of the line will be ignored (not executed)

You can also use # for single-line comments, but in this tutorial, we’ll use //.

The following examples demonstrate a single-line comment as an explanation:

Example

A comment preceding the code:

// Outputs a welcome message:
echo "Welcome Home!";

 

Example

A comment at the end of a line:

echo "Welcome Home!"; 
// Outputs a welcome message

Comments to Ignore Code

We can use comments to stop certain lines of code from being executed:

 

Example

Do not show a welcome message.

// echo "Welcome Home!";