Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the programming statements of PHP

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you what PHP programming sentences are, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

1 simple statement

Each line contains at most one statement, such as:

The following is the referenced content:

$argv++; / / correct $argc--; / / correct $argv++; $argc--; / / wrong

2 compound statement

A compound statement is a sequence of statements enclosed in curly braces, shaped like "{statement}". For example, the following paragraphs.

The included statement should be indented one level more than the compound statement.

The opening brace "{" should be at the end of the line at the beginning of the compound statement; the right brace "}" should be on another line and aligned with the first line of the compound statement.

Curly braces can be used for all statements, including individual statements, as long as they are part of a control structure such as if-else or for. This makes it easy to add statements without having to worry about introducing bug because you forgot to add parentheses

3 return statement

A return statement with a return value does not use parentheses "()" unless they make the return value more visible in some way. For example:

The following is the referenced content:

Return; return myDisk.size (); return ($size? $size: $defaultSize)

4 if and else statements

The if-else statement should have the following format:

If (condition) {/ * conditions for operation * / statements;} if (condition) {/ * conditions for operation. * / statements;} else {/ * conditions for operation * / statements;} if (condition) {/ * conditions for operation * / statements;} else if (condition) {/ * conditions for operation * / statements;} else {/ * conditions for operation * / statements;}

Note: if statements are always enclosed in "{" and "}" to avoid using the following error-prone formats:

If (condition) / / avoids this writing, ignoring the "{}" statement

The comment format can also be written in the following way

The following is the referenced content:

If (condition) {/ * conditions for operation * / statements;} else {/ * conditions for operation * / statements;}

You can write comments anywhere as long as you can clearly describe the relationship between the branches.

5 for statement

A for statement should have the following format:

The following is the referenced content:

For (initialization; condition; update) {statements;}

An empty for statement (all work is done in initialization, conditional judgment, update clause) should have the following format:

For (initialization; condition; update)

Avoid increasing complexity by using more than three variables when using commas in initialization or update clauses of for statements. If desired, you can use separate statements before the for loop (for initialization clauses) or at the end of the for loop (for update clauses).

6 while statement

A while statement should have the following format

The following is the referenced content:

While (condition) {statements;}

An empty while statement should have the following format:

While (condition)

7 do...while statement

A do-while statement should have the following format:

The following is the referenced content:

Do {statements;} while (condition)

8 switch statement

A switch statement should have the following format:

The following is the referenced content:

Switch (condition) {case ABC: / * falls through * / statements; case DEF: statements; break; case XYZ: statements; break; default: statements; break;}

Whenever a case executes down (because there is no break statement), comments should usually be added to the location of the break statement. The above sample code contains the comment / * falls through * /.

9 try...catch statement

A try-catch statement should have the following format:

The following is the referenced content:

Try {statements;} catch (ExceptionClass e) {statements;}

A try-catch statement may also be followed by a finally statement, which will be executed regardless of whether the try block is successfully executed or not.

The following is the referenced content:

Try {statements;} catch (ExceptionClass e) {statements;} finally {statements;} these are all the contents of the article "what are the programming sentences for PHP". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report