Home  >  Article  >  Backend Development  >  PHP file format specification

PHP file format specification

WBOY
WBOYOriginal
2016-08-08 09:22:221739browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn