简体   繁体   中英

How can I comment this particular block of PHP code?

How would I go about commenting all of this code when it has breaks in the PHP sections?

If I wrap /* */ around it, it doesn't work.

Obviously I can make it work by not being lazy, but if I want to be lazy... How might you comment this whole block?

if($fields){
    ?>
        <ul>
            <?php
                foreach($fields as $field){
                    ?>
                        <li>
                            <?php
                                /* if($field['label']){
                                    echo $field['label'];
                                } */
                                print_ext($field);
                            ?>
                        </li>
                    <?php
                }
            ?>
        </ul>
    <?php
}

You can't. You should just avoid coding like that altogether as it creates a horribly unreadable mess.

You can't really but you can turn it off pretty easily.

if($fields && false){
    ?>
        <ul>
            <?php
                foreach($fields as $field){
                    ?>
                        <li>
                            <?php 
                                /*if($field['label']){
                                    echo $field['label'];
                                }*/
                                print_ext($field); 
                            ?>
                        </li>
                    <?php                                                        
                }
            ?>
        </ul>
    <?php
} 

The following solution should work. You might have issues if you are wrapping the comments that exist already around if($field['label']) so I have deleted them as shown below.

<?php
/*
if($fields){
    ?>
        <ul>
            <?php
                foreach($fields as $field){
                    ?>
                        <li>
                            <?php 
                                if($field['label']){
                                    echo $field['label'];
                                }
                                print_ext($field); 
                            ?>
                        </li>
                    <?php                                                        
                }
            ?>
        </ul>
    <?php
} 
*/
?>

For more information look at this answer .

Not really commenting, but you can disable this block like this (almost no matter its content):

<?php $bar = <<<'EOD'
if($fields && false){
  ?>
    <ul>
    <?php
    foreach($fields as $field){
      ?>
        <li>
        <?php
        /*if($field['label']){
          echo $field['label'];
          }*/
        print_ext($field);
      ?>
        </li>
        <?php
    }
  ?>
    </ul>
    <?php
}
EOD;

将您的HTML放入PHP open / close标记中,然后/ * * /将可以正常工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM