php注释代码_如何以及为什么在您PHP代码中进行注释

php注释代码

A comment in PHP code is a line that is not read as part of the program. Its only purpose is to be read by someone who is editing the code. So why use comments?

PHP代码中的注释是不作为程序一部分读取的行。 其唯一目的是由正在编辑代码的人员阅读。 那么为什么要使用注释呢?

  • To let others know what you're doing. If you are working with a group of people or plan on anyone else ever using your script, the comments tell the other programmers what you were doing in each step. This makes it much easier for them to work with and to edit your code if needed.

    让别人知道你在做什么 。 如果您正在与一群人一起工作或计划使用脚本的其他人,则注释会告诉其他程序员您在每个步骤中都在做什么。 这使他们可以更轻松地使用和编辑您的代码(如果需要)。

  • To remind yourself what you did. Although you may just be writing a quick script for yourself and don't see the need for comments, go ahead and add them in anyway. Most programmers have experienced coming back to edit their own work a year or two later and having to figure out what they did. Comments can remind you of your thoughts when you wrote the code.

    为了提醒自己您做了什么。 尽管您可能只是在为自己编写一个快速脚本,看不到需要注释,但是请继续添加它们。 大多数程序员都经历过一两年后再来编辑自己的工作,不得不弄清楚自己做了什么。 注释可以使您想起编写代码时的想法。

There are several ways to add a comment in PHP code. The first is by using // to comment out a line. This one-line comment style only comments to the end of the line or the current code block, whichever comes first. Here is an example:

有几种方法可以在PHP代码中添加注释。 第一种是使用//注释掉一行。 这种单行注释样式仅注释到该行的末尾或当前代码块,以先到者为准。 这是一个例子:

 <?php 
 echo "hello"; 
 //this is a comment 
 echo " there"; 
 ?> 

If you have a single line comment, another option is to use a # sign. Here is an example of this method:

如果您有单行注释,则另一个选择是使用#号。 这是此方法的示例:

 <?php 
echo "hello"; 回声“你好”; #this is a comment #这是一条评论 echo " there"; 回声“那里”; ?> ?>

If you have a longer, multi-line comment, the best way to comment is with /* and */ before and after a lengthy comment. You can contain several lines of commenting inside a block. Here is an example:

如果您有较长的多行注释,最好的注释方法是在较长的注释前后加上/ *和* /。 您可以在一个块中包含多行注释。 这是一个例子:

 <?php 
 echo "hello"; 
 /* 
 Using this method 
 you can create a larger block of text 
 and it will all be commented out 
 */ 
 echo " there"; 
 ?> 

不要混淆评论 ( Don't Mix Comments )

Although you can nest comments within comments in PHP, do so carefully. Not all of them nest equally well. PHP supports C, C++ and Unix shell-style comments. C style comments end at the first */ they encounter, so don't nest C style comments. 

尽管您可以在PHP的注释中嵌套注释,但请谨慎进行。 并非所有人都嵌套得很好。 PHP支持C, C ++和Unix Shell样式的注释。 C样式注释在它们遇到的第一个* /结尾处结束,因此不要嵌套C样式注释。

If you are working with PHP and HTML, be aware that HTML comments mean nothing to the PHP parser. They won't work as intended and are likely to execute some function. So, stay away from: 

如果您使用的是PHP和HTML,请注意HTML注释对PHP解析器毫无意义。 它们将无法按预期工作,并且可能会执行某些功能。 因此,请远离:

<!--Comment-->

翻译自: https://www.thoughtco.com/how-and-why-to-comment-your-php-code-2693948

php注释代码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值