Author: Hua honglang
Body:
I have introduced the basic HTML syntax in the article about HTML syntax. A static web page can be compiled, and dynamic interaction information is very important. For example, the Membership registration and logon of some websites require the running of backend programs. CGI programs used by many websites are mainly written in Perl, ASP, Java, and PHP, and all we need is PHP. It is completely free of license fees. Thanks to the obscure programmers. The structure of PHP is similar to that of C language, which proves that "one learning, programming everywhere" in C language ". I believe that people who have learned the C ++ language can easily get started with PHP. Let's introduce some PHP syntaxes first. This article is suitable for beginners.
PHP differs from C, or it may be more flexible to some extent than C. In C, variables must be defined before they can be used. In PHP, variables are directly used without the need to be defined in advance. Variable types are automatically generated when values are assigned. PHP variables include INTEGER (int), double, string, array, and object ).
When the integer size exceeds the value range, it is automatically converted to the Double Precision type. The value range is as follows:
┌ ── ─ ┬ ── ─
│ Declared type │ length (BITs) │ length (bytes) │ value range │
├ ── ─ ┼ ── ─
│ Int │ 32 │ 4 │-2147483647 ~ 2147483647 │
├ ── ─ ┼ ── ─
│ Double │ 32 │ 4 │ 1.7E-308 ~ 1.7E + 308 │
└ ── ─ ┴ ── ─
String, usually expressed by "" (double quotation marks. It can also be expressed by '(single quotes) as follows:
$ A = "abc ";
$ B = "abc $ ";
$ C = 'abc $ ';
$ D = "\" cde \"";
$ E = '"cde "';
Various variables in PHP Add "$" before the variable name to show the difference.
Note that the content of $ B is abcabc, $ c is abc $ a, $ d is "cde", and $ e is "cde ". It can be seen that the variable name in double quotation marks will be replaced by the variable name, but not in single quotation marks. The content in double quotation marks must be escaped, for example, $ Application \ $, but not in single quotation marks.
The array syntax in PHP is:
Array name [Index]
Indexes can be numbers or text. However, it is not recommended to use text because it is of little significance. Arrays are more flexible than other languages, as shown in the following example:
<? Php
$ Names [] = 100;
$ Names [] = 200;
$ Names [] = "hi, how are you ";
$ Names [] = 98.5;
$ Names [] = 1.7E + 23;
$ Num = count ($ names );
For ($ I = 0; $ I <= $ num; $ I ++ ){
Echo "$ names [$ I] <br> ";
}
?>
It can be seen that the elements in an array are not necessarily of the same type, which is the "active" position of the PHP array.
Using objects makes programmers easier to maintain and programs easier to read. Compared with other languages, PHP is much simpler. It only includes class, method, attr extends ibute, and extendsions.
In the previous article, we talked about only the data types of PHP. The so-called "cutting power without mistake" can lay a solid foundation for PHP to better learn PHP programming.
The expressions and operators in PHP are not much different from those in C language. Now, they are listed below:
┌ ── ─ ┬ ── ─
│ Operator │ example │
├ ── ─ ┼ ── ─
│ + │ Addition │ $ a + $ B │
├ ── ─ ┼ ── ─
│-│ Subtraction │ $ a-$ B │
├ ── ─ ┼ ── ─
│ * │ Multiplication │ $ a * $ B │
├ ── ─ ┼ ── ─
│/│ Division │ $ a/$ B │
├ ── ─ ┼ ── ─
│ % │ Obtain the remainder │ $ a % $ B │
├ ── ─ ┼ ── ─
│ ++ │ Incremental │ $ a ++ or ++ $ a │
├ ── ─ ┼ ── ─
│ -- │ Decrease │ $ a -- or -- $ a │
├ ── ─ ┼ ── ─
│ ==│ Equals │ $ a == 10 │
├ ── ─ ┼ ── ─
│ ===│ Equals │ $ a === 10 │
├ ── ─ ┼ ── ─
│! = │ Not equal to │ $! = 10 │
├ ── ─ ┼ ── ─
│ <│ Less than │ $ a <9 │
├ ── ─ ┼ ── ─
│> │ Greater than │ $ a> 8 │
├ ── ─ ┼ ── ─
│ <= │ Less than or equal to │ $ a <= 10 │
├ ── ─ ┼ ── ─
│ >=│ Greater than or equal to │ $ a >=1 │
├ ── ─ ┼ ── ─
│ = │ Equal value assignment operator │ $ a = 0 │
├ ── ─ ┼ ── ─
│ + = │ Addition specified operator │ $ a + = 5 │
├ ── ─ ┼ ── ─
│-= │ Subtraction specified operator │ $ a-= 1 │
├ ── ─ ┼ ── ─
│ * = │ Multiplication specified operator │ $ a * = 2 │
├ ── ─ ┼ ── ─
│ // = │ Division specified operator │ $ a/= 5 │
├ ── ─ ┼ ── ─
│ % = │ Remainder specified operator │ $ a % = 7 │
├ ── ─ ┼ ── ─
│. = │ String specified operator │ $ a. = "hello" │
├ ── ─ ┼ ── ─
│ & │ And │ $ a & $ B │
├ ── ─ ┼ ── ─
│ | │ Or │ $ a | $ B │
├ ── ─ ┼ ── ─
│ ^ │ Xor │ $ a ^ $ B │
├ ── ─ ┼ ── ─
│ ~ │ Non-│ ~ $ A (obtain the complement Code of 1) │
├ ── ─ ┼ ── ─
│ <│ Shift left │ $ a <$ B │
├ ── ─ ┼ ── ─
│ >>│ Shift to the right │ $ a >> B B │
├ ── ─ ┼ ── ─
│ And or & │ and │ $ a and $ B or $ a & $ B │
├ ── ─ ┼ ── ─
│ Or | │ or │ $ a or $ B or $ a | $ B │
├ ── ─ ┼ ── ─
│ Xor │ Xor │ $ a xor $ B │
├ ── ─ ┼ ── ─
│! │ Non-│! $ A │
└ ── ─ ┴ ── ─
┌ ── ─ ┬ ── ─ ┐
│ Symbol │ meaning │
├ ── ─ ┼ ── ─ ┤
│ $ │ Variable │
├ ── ─ ┼ ── ─ ┤
│ & │ Pointer to the variable (before the variable) │
├ ── ─ ┼ ── ─ ┤
│-> │ Method or attribute of the object │
├ ── ─ ┼ ── ─ ┤
│ => │ Element value of the array │
├ ── ─ ┼ ── ─ ┤
│? : │ Ternary operator │
└ ── ─ ┴ ── ─ ┘
Compare it with the C language. Only the "." operator is added. It connects two strings. For example, the result is hello, my baby.
<? Php
$ A = "hello ,";
$ B = "my baby .";
Echo $ a. $ B;
?>
Another symbol also makes PHP powerful. This is "$ ". It is used before A variable, indicating that it is A variable, such as $ A and $ B. So where is its role strong? This variable is the variable.
For example:
<? Php
$ A = "go ";
$ A = "here ";
Echo $;
Echo $;
Echo $ go;
?>
The result is as follows:
Go
Here
Here
In fact, adding "$" to a variable is to use the content of this variable as a new variable name. This is unique to PHP and sometimes simplifies the program.
-- (To be continued )--