Home > Article > Backend Development > PHP file format specification
PHP file format specification
PHP specification
1. if…else… way of writing
<code>if (true) { // Code here... } else { // Code here... } 注意: if 与()保持一个空格, () 与 { 在同一行,且保持一个空格 </code>
2. if…elseif…else way of writing
<code>if (true) { // Code here... } elseif (true) { // Code here... } else { // Code here... } </code>
Old
1. For files that only contain php code, we will write it in the file Ignore the "?>" at the end. This is to prevent extra spaces or other characters from affecting the code. Break a new line at the end of the code file and end it with // end
<code>例: <?php $localtime = date('y-m-d H:i:s',time()); $test = 'test'; echo $localtime.$test; ... // end </code>
2. Indentation should be able to reflect the logical results of the code. Use TAB for indentation. Leave gaps (add spaces) before and after each statement and the beginning of the brace.
<code>例: <?php $t = date("H"); if ($t<20) { echo 'Have a good day!'; } else { echo 'Good night'; } ... // end </code>
The above introduces the PHP file format specifications, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.