PHP entry-level tutorial: how to quickly learn PHP language _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Tags switch loop
PHP entry-level tutorial: teaches you how to quickly learn the PHP language. LieHuo. Net programming document This article introduces some PHP entry-level tutorials: quick learning of PHP. PHP syntax. 1. embedding method: like ASP %. can PHP be? Php or Bkjia. ComPHP entry-level tutorial: learn PHP quickly.

  PHP syntax.

1. embedding method:

PHP, similar to ASP, can be Of course, you can also specify it yourself.

2. Reference File:

There are two methods to reference files: require and include.
The use of require is as follows: require ("MyRequireFile. php ");. This function is usually placed at the beginning of the PHP program. before the PHP program is executed, it will first read the file specified by require to make it a part of the PHP program webpage. This method can also be used to introduce common functions into webpages.

Include usage methods such as include ("mydomaindefile. php ");. This function is generally placed in the process of process control. The PHP program webpage reads the include file. In this way, you can simplify the process during program execution.

3. annotation method:

Reference content is as follows:
Echo "this is the first example. N "; // This example is a C syntax comment
/* This example uses multiple rows
Annotation method */
Echo "this is the second example. N ";

Echo "this is the third example. N "; # This example uses UNIX Shell syntax annotations

4. variable type:

Reference content is as follows:
$ Mystring = "I am a string ";
$ NewLine = "line feed n ";
$ Int1 = 38;
$ Float1 = 1.732;
$ Float2 = 1.4E 2;
$ MyArray1 = array ("child", "ugly", "Yin", "Mao ");

Two problems are raised here. First, the PHP variable starts with $, and the second PHP statement ends with;, which may be unsuitable by ASP programmers. These two omissions are also the cause of many program errors.

5. operator number:

Mathematical operations: Symbolic meaning
Addition operation
* Multiplication
% Obtain the remainder

String operation:

There is only one operator number, which is an English ending. It can be used to connect strings and convert them into new merged strings. Similar &

Reference content is as follows:
$ A = "PHP 4 ″;
$ B = "powerful ";
Echo $ a. $ B;

Two problems are also raised here. the output statement in PHP is echo, and the second is similar to <% = variable %> in ASP. PHP can also .

Logical operation:

Symbolic meaning
> Greater
<= Less than or equal
> = Greater than or equal
= Equal
! = Not equal
& And (And)
And (And)
| Or (Or)
Or (Or)
Xor exclusive or (Xor)
! No (Not)

Php process control

1. if... else loop has three structures

The first is to use the if condition as a simple judgment. It is interpreted as "how to deal with something if something happens ". Syntax:


If (expr) {statement}

Expr is the judgment condition, which is usually determined by the logical operator number. Statement is the execution part of the program that meets the conditions. if the program has only one line, you can omit braces {}.

Example: braces are omitted in this example.


The following content is referenced by the Institute of fire station construction:
If ($ state = 1) echo "haha ";

It is important to note that, to determine whether the equality is equal to = rather than =, ASP programmers may often make this mistake, = is a value assignment.

Example: the execution part of this example has three rows and the braces cannot be omitted.


Reference content is as follows:
If ($ state = 1 ){
Echo "haha;

In addition to the if clause, the first two conditions of else can be interpreted as "what to do if something happens, otherwise how to solve it ". Syntax:

If (expr) {statement1} else {statement2} example: the above example is modified to a more complete processing. Because else only executes one line of commands, no braces are added.

Reference content is as follows:
If ($ state = 1 ){
Echo "haha ";
Else {
Echo "haha ";

The third type is the recursive if... else loop, which is usually used for multiple decision making decisions. It combines several if... else values for processing.

Let's look at the example below.

Reference content is as follows:
If ($ a> $ B ){
Echo "a is larger than B ";
} Elseif ($ a ==$ B ){
Echo "a is equal to B ";
} Else {
Echo "a is smaller than B ";

In the above example, we only use the layer-2 if .. else loop to compare the two variables a and B. Actually, we need to use this recursion if .. please be careful when using else loops, because too many layers of loops may cause problems in the design logic, or if you leave less braces, the program may encounter inexplicable problems.

2. there is only one for loop without any change. Its syntax is as follows:

For (expr1; expr2; expr3) {statement}

Expr1 is the initial value of the condition. Expr2 is the condition for judgment. it is usually determined by a logical operator number (logical operators. Expr3 is the part to be executed after statement is executed. it is used to change the condition for the next loop judgment, such as adding one. Statement is the execution part of the program that meets the conditions. if the program has only one line, you can omit braces {}.

The following is an example of using for loop writing.

Reference content is as follows:
For ($ I = 1; $ I <= 10; $ I ){
Echo "this is the first". $ I. "Loop

3. switch loop, usually processing compound condition judgment. each sub-condition is part of the case instruction. In practice, if many similar if commands are used, they can be combined into a switch loop.


Switch (expr) {case expr1: statement1; break; case expr2: statement2; break; default: statementN; break ;}

The expr condition, usually the variable name. The exprN after case usually represents the variable value. The part that meets the condition after the colon. Note that you must use the break to skip the cycle.

Reference content is as follows:
Switch (date ("D ")){
Case "Mon ":
Echo "today Monday ";
Case "Tue ":
Echo "Today's Tuesday ";
Case "Wed ":
Echo "Wednesday ";
Case "Thu ":
Echo "Thursday ";
Case "Fri ":
Echo "Today's Friday ";
Echo "today's holiday ";

Here, you need to note break; do not miss it, default. it is acceptable to omit it.

Obviously, it is very troublesome to use the if loop in the above example. Of course, in the design, the conditions with the highest probability should be placed at the beginning, and the minimum conditions should be placed at the end, which can increase the execution efficiency of the program. In the previous example, because the probability of occurrence is the same every day, you do not need to pay attention to the order of conditions.

Build a database

In ASP, if it is an ACCESS database, you can directly open ACCESS to edit the MDB file. if it is an SQL server, you can open the Enterprise Manager to edit the SQL SERVER database, but in PHP, the command line editing of my SQL may be very troublesome for beginners. it doesn't matter. you can download and install PHPMYADMIN, and you can rely on it to create and edit a database later.

The following describes how to use it.
After entering phpmyadmin, we first need to create a database, Language (*) Here select simplified Chinese, then create a new database on the left here fill in the database name, click create.

Select the created database from the drop-down list on the left. In the following

Create a new table in the database shop:
Number of fields:

Enter the table name and the approximate number of fields you think (it doesn't matter if it is not enough or more, you can add it later or use the default value), and click execute.
Then you can create a table.
The first column is the field name, and the second column selects the field type:
We usually use the following:
1) VARCHAR, text type
2) INT, integer type
3) FLOAT, floating point type
4) DATE, DATE type
5) You may ask, where is the automatically added ID? You only need to select the INT type, and select auto_increment in the additional section below.

  • Three pages in total:
  • Previous Page
  • 1
  • 2
  • 3
  • Next page

This article introduces some PHP entry-level tutorials: quick learning of PHP. PHP syntax. 1. embedding method: like ASP %. can PHP be? Php or...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.