2016-05-31 72 views
-1

对于php函数代码,您如何评论代码?这是正确的还是最好的方法?你如何评论PHP功能内的代码?

function menu_element_builder($values) { 
//$links = ''; 
} 
+1

//和/ * * /。我不知道如果在评论代码最好的方法:d – user489872

+1

那么,如果你需要注释掉的代码,你应该问自己,为什么你需要它?如果你不只是可以删除它。 – Rizier123

+0

我只是不确定语法是否在函数内部工作。现在我明白了! – DDJ

回答

3

注释行//#,由您决定。

注释部分行或全部代码块,其中/* [commented code] */

function menu_element_builder($values/*, $optional_value*/) { 
    #Commented out line 
    echo "Not commented out";  

    //Commented out line 
    echo "Not commented out"; 

    /* Commented out code block 
    echo "Commented out"; */ 

    echo "Not commented out"; //but this is ." and so's this"; 
    echo "Not commented out" /* but this is */ ." and this isn't"; 
    /* This is commented out */ echo "But this isn't"; 
} 
+1

不要使用#,我相信它已被弃用。使用//或/ * */ – Nitin

+1

@Nitin它在.ini文件中仅被弃用。它适用于PHP文件。 – Xatenev

+1

@Nitin其实他们不是 - 他们只在'.ini'文件中被弃用。 [来源](http://php.net/manual/en/migration53.deprecated.php) – Ben

0
<?php 
// This is a single-line comment 

# This is also a single-line comment 

/* 
This is a multiple-lines comment block 
that spans over multiple 
lines 
*/ 

// Aswell you can use comments to hide part of your code from execution 
$x = 5 /* + 15 */ + 5; 
echo $x; 
?>