在PHP中,有三种方法可以注释代码:
1. 单行注释:用双斜杠(//)注释一行代码。
例如:
```
// This is a comment
echo "Hello World!";
```
2. 多行注释:用斜杠加星号(/*)表示注释开始,用星号加斜杠(*/)表示注释结束。
例如:
```
/* This is a
multi-line comment */
echo "Hello World!";
```
3. 文档注释:用斜杠加星号加两个星号(/**)开始和结束注释,可以用在函数、类、方法等上方,用于生成文档。
例如:
```
/**
* This function calculates the sum of two numbers.
*
* @param int $a
* @param int $b
* @return int
*/
function sum($a, $b) {
return $a + $b;
}
```
Copyright © 2025 IZhiDa.com All Rights Reserved.
知答 版权所有 粤ICP备2023042255号