PHP - Introduction Comments

Introduction

PHP comment is text that is ignored by the PHP engine.

The purpose of comments is to add messages to yourself and other programmers that explain what your code does.

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

To write a single-line comment, start the line with either two slashes (//) or a hash symbol (#).

For example:

// This code displays the current time
# This code displays the current time

To write multi-line comments, start the comment with a slash followed by an asterisk (/*) and end the comment with an asterisk followed by a slash (*/), as follows:

/*
This code displays the
current time in a nice,
easy-to-read format.
*/

So you might comment the PHP code like this:


<?php
         // Get the current time in a readable format
         $currentTime = date( "g:i:s a" );

         // Display greeting and time to the visitor
         echo "Hello, world! The current time is $currentTime";
?>