Comments program में line of code होता है जो कि execute नहीं होता है, जिससे कि जब दुबारा हम उस program पर काम करे तो हर step हमें समझ आ सके कि हमने इसमें किया क्या था। Comments single Line भी हो सकते है और Muliline भी हो सकते हैं।

PHP में Comments दो तरह के होते है

Single Line Comments

PHP में single line comment हम दो तरह से लिख सकते हैं //comments और #comments

Example -

File : comment.php

Copy Fullscreen Close Fullscreen
<?php  
  //single line comment
  $x = "This is single line Comment";
  # this is also a comment.
  echo $x;
?>
Output
This is single line Comment

Multi Line Comments

multi line comment लिखने के लिए slash asterisk /* से start करते हैं और asterisk slash */ से end करते है।

File : comment2.php

Copy Fullscreen Close Fullscreen
<?php  
  $x = "This is multi line Comment"; 
  /*this is multi line comment 
     blah blah blah */  
  echo $x;
?>
Output
This is multi line Comment

Why Should We Use Comments ?

  • किसी भी project पर काम करने के बाद हमें जरूरत के हिसाब से समय के साथ उसमे changes करने पढ़ ही जाते हैं तो जब हम update करें तो हमें proper पता चले कि हमने किया क्या था।

  • या जब कोई दूसरा programmer हमारे द्वारा develop किये गए project को देखे या update करे तो उसे भी पता चले।

  • Comment लिखना आपकी Coding Standardization को भी बताता है।

  • कमेंट लिखने से Coding Readability भी बढ़ती है।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers