Comments Used In PHP

If you are a PHP web developer, then, you surely want to build any web program using the PHP programming language. But, what about the complexity of the project? Will it be complex and would it be easy to debug them in future? Well, the answer to this will be about how you have built up that project. To make your PHP project much easy, one of the method on it would be by writing the comments to the respective function would be a great way to program your PHP code, since, if you add comments, then, you can remember that what is that function being built for in the future.

Well, after knowing the importance of PHP comments, you might need to know about how to add the comments in your PHP project. Hence, here, we are describing the different way to write the PHP comments. Also, it is a way to remember that what a function does, even after a year and more. So, writing a PHP comments is great. Also, the other thing is that, the PHP comments are not displayed in the HTML output file. The advantage of this would be, that the visitors will not know anything about how certain function is build and its functionality for the specific website. There are two ways to write a PHP comments, which are described below:

Single Line Comment

It is the comment written in PHP which only affects the single line after the comment syntax is written. These are of two types:

  1. //
  2. #

The basic syntax for // and # is provided below respectively:

Double Line Comment

It is the comment written in PHP which affects two or more than two lines after the comment syntax is written. The basic syntax is provided below:

The example for the PHP comment in the HTML document file is provided below:

comments-in-php

The above image shows the details on the output for the above PHP code comments, when it is executed. Here, in the above image, the top one is of the outputted data in browser, and the below one is of the whole source code outputted in HTML format from the above PHP code. Here, you can see that the PHP comments has been removed from the output window as well as from the outputted HTML format.

Now, if you have followed the above example properly in your development environment or in your PHP project, then, we can assume that you have learnt about writing comments in PHP progrmming language and will follow this in your developing or developed PHP projects.

, , , , , , , , , , , , , , , , , , ,

Post navigation

Bishal Napit

Bishal Napit is a WordPress theme developer from Tansen, Palpa, with a passion to learn more on WordPress.

Leave a Reply