comment php code code example

Example 1: php comment

// 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
*/

Example 2: comment in php

<?php
 /*
    echo 'This is a test'; /* This comment will cause a problem */
 */
?>

Example 3: php proper function comments

/**
 * This function compiles a message that tells you how great coffee is
 *
 * @param string  $compliment A nice word to describe coffee 
 * @param integer $score      A score out of 10
 */

Example 4: php comment

<?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
*/
  
// You can also use comments to leave out parts of a code line
$x = 5 /* + 15 */ + 5;
echo $x;
?>

Example 5: comment 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
*/

Example 6: comment in php

A nice way to toggle the commenting of blocks of code can be done by mixing the two comment styles:
<?php
//*
if ($foo) {
  echo $bar;
}
// */
sort($morecode);
?>

Now by taking out one / on the first line..

<?php
/*
if ($foo) {
  echo $bar;
}
// */
sort($morecode);
?>
..the block is suddenly commented out.
This works because a /* .. */ overrides //. You can even "flip" two blocks, like this:
<?php
//*
if ($foo) {
  echo $bar;
}
/*/
if ($bar) {
  echo $foo;
}
// */
?>
vs
<?php
/*
if ($foo) {
  echo $bar;
}
/*/
if ($bar) {
  echo $foo;
}
// */
?>

Tags:

Html Example