Bkjia.Com Programming Documentation This article will introduce some PHP entry-level tutorials: Learn PHP quickly.
PHP syntax.
1. Embedding method:
Similar to ASP's <%, PHP can be . Of course, you can also specify it yourself.
2. Cited documents:
There are two ways to reference files: require and include.
Require is used as require(”MyRequireFile.php”);. This function is usually placed at the front of the PHP program. Before the PHP program is executed, it will first read in the file specified by require and make it a part of the PHP program web page. Commonly used functions can also be introduced into web pages in this way.
include is used like include(”MyIncludeFile.php”);. This function is generally placed in the processing part of flow control. The PHP program web page only reads the include file when it reads it. In this way, the process of program execution can be simplified.
3. Annotation method:
The following is the quoted content:
/* This example uses a multi-line comment */echo "This is the second example. n";
|
4. Variable type:
The following is the quoted content: $mystring = "I am a string " ; $NewLine = "Newline n" ; $int1 = 38 ; $float1 = 1.732 ; $float2 = 1.4E 2 ; $MyArray1 = array( " " , " Chou " , " Yin " , " Mao " ); |
5. Operation symbols:
Mathematical operations: Symbol Meaning
以下为引用的内容: $a = “PHP 4″ ; |
/ Division
% Remainder Accumulation
– Decrement
String operations:
There is only one operator symbol, which is the English period. It can concatenate strings into new merged strings. Similar to &
in ASP
The following is the quoted content: $a = “PHP 4″; $b = “Powerful”; echo $a.$b; ?> |
Logical operations:
Symbol meaning
< Less than
> Greater than<= Less than or equal to
if (expr) { statement } |
Where expr is the condition for judgment, usually logical operation symbols are used as the condition for judgment. The statement is the execution part of the program that meets the conditions. If the program has only one line, the curly brackets {} can be omitted.
Example: This example omits the curly braces.
以下为烈火建站学院引用的内容: if ($state==1)echo “哈哈” ; ?> Special attention here is that the judgment of equality is == instead of =. ASP programmers may often make this mistake, = is assignment. Example: The execution part of this example has three lines, and the curly brackets cannot be omitted.
The second type is to add an else condition in addition to if, which can be interpreted as "how to deal with something if something happens, otherwise how to solve it." The syntax is as follows if (expr) { statement1 } else { statement2 } Example: Modify the above example into a more complete process. Since there is only one line of instructions for executing else, there is no need to add braces.
The third type is the recursive if..else loop, which is usually used in various decision-making judgments. It combines several if..else statements for processing. Look directly at the example below
The above example only uses a two-level if..else loop to compare the two variables a and b. When actually using this kind of recursive if..else loop, please use it with caution, because too many levels of loops can easily cause problems with the design logic, or missing braces, etc., can cause inexplicable problems in the program. 2. There is only one type of for loop with no changes. Its syntax is as follows for (expr1; expr2; expr3) { statement } where expr1 is the initial value of the condition. expr2 is the condition for judgment, and logical operators are usually used as the condition for judgment. expr3 is the part to be executed after statement is executed. It is used to change the conditions for the next loop judgment, such as adding one, etc. The statement is the execution part of the program that meets the conditions. If the program has only one line, the curly brackets {} can be omitted. The following example is written using a for loop.
3. The switch loop usually handles compound conditional judgments. Each sub-condition is part of the case instruction. In practice, if many similar if instructions are used, it can be synthesized into a switch loop. The syntax is as follows switch (expr) { case expr1: statement1; break; case expr2: statement2; break; default: statementN; break; } The expr condition is usually a variable name. The exprN after case usually represents the variable value. After the colon is the part to be executed that meets the condition. Be sure to use break to break out of the loop.
What needs to be noted here is break; don’t omit it, default, it’s okay to omit it. Obviously, using the if loop in the above example is very troublesome. Of course, when designing, you should put the conditions with the greatest probability of occurrence at the front and the conditions with the least occurrence at the end, which can increase the execution efficiency of the program. In the above example, since the probability of occurrence is the same every day, there is no need to pay attention to the order of the conditions. Build database In ASP, if it is an ACCESS database, you can directly open ACCESS to edit the MDB file. If it is a SQL SERVER, you can open the Enterprise Manager to edit the SQL SERVER database. However, in PHP, the command line editing of MY SQL may It's very troublesome for beginners. It doesn't matter. You can download PHPMYADMIN and install it. You can rely on it to build and edit the database in the future. Let’s talk about its use below. Then select the created database in the drop-down menu on the left. belowCreate a new table in the database shop: Fill in the table name and the approximate number of fields you think (it doesn’t matter if there are not enough or too many, you can add them later or default them), and press Execute.
Related labels:
source:php.cn
Previous article:Some applications of Smarty in template files_PHP tutorial
Next article:Top Ten Tips to Improve Your PHP Application Strength_PHP Tutorial
Statement of this Website
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
Latest Articles by Author
Latest Issues
Group MySQL results by ID for looping over
I have a table with flight data in mysql. I'm writing a php code that will group and displ...
From 2024-04-06 17:27:56
0
1
406
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
|