PHP TUTORIALPHP TutorialPHP InstallationPHP Hello WorldPHP Basic SyntaxPHP CommentsPHP VariablesPHP Variable ScopePHP ConstantsPHP StringsPHP OutputPHP Data TypesPHP Type CastingPHP OperatorsPHP ConditionalsPHP Shorthand ConditionalsPHP LoopsPHP Loop Control StructuresPHP FunctionsPHP String FunctionsPHP ArraysPHP Superglobal VariablesPHP in HTMLPHP RegexRegex IntroductionRegex PCRE SyntaxPHP PREG FunctionsPHP FormsPHP Forms IntroductionPHP Forms CreatingPHP Forms SecurityPHP Forms ValidationPHP Forms Required InputsPHP Forms StickyPHP Forms Advanced ValidationPHP Forms FinishingPHP OOPPHP Object Oriented ProgrammingPHP OOP ClassesPHP OOP PropertiesPHP OOP ObjectsPHP OOP MethodsPHP OOP $this KeywordPHP OOP Constructors and DestructorsPHP OOP VisibilityPHP OOP InheritancePHP OOP Abstract Classes and MethodsPHP OOP Interfaces

PHP Comments

Good programmers write perfect code with plenty of comments.

PHP parser ignores all the comments.

There are two ways of commenting


PHP Comments Example


<?php

// this is a single-line comment

# this is a single-line comment too

/*
	This is a multi-line comment
	This line is a comment
*/

// to remove a part of code
echo 5 /* + 2 */  + 5;

Run Example ››

Block Comments

Developers use a special way of commenting to make it easy to understand when you read it again. Note that this is not a rule, but an effective way of increasing the readability of your comments. This is called block comments. Here's the common way of writing block comments.

PHP Block Comments


<?php
/**
* This is a block comment
* The first line starts with the normal /* and one more *
* All the next lines starts with *
* Finally, it ends with * and / in the last line
*/

Run Example ››

Block comments are used to provide verbose information about variables, functions, and more. We will learn how to use them in a real world script in the next chapters.

Facebook Twitter