2016-05-31 36 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; 
?>