Home  >  Article  >  Backend Development  >  A brief discussion of PHP syntax 1_PHP tutorial

A brief discussion of PHP syntax 1_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:27:35797browse

In the article "Talk about HTML syntax", I have introduced basic HTML syntax. It is possible to compile a static Web page, but it is very important to dynamically interact information. For example, the membership system of some websites requires the operation of back-end programs for member registration and login. The CGI programs used by many websites are mainly written in Perl, ASP, Java, and PHP, and what we are going to use is PHP. It's completely free, thanks to those obscure programmers. The structure of PHP is similar to the C language, which is in compliance with the "learn in one place, program anywhere" mentioned in the C language. I believe that people who have learned the C language can easily get started with PHP. Let’s introduce some PHP syntax first. This article is suitable for beginners to learn.
There are also some differences between PHP and C language, or it may be more flexible than C language to some extent. In C language, variables must be defined before they can be used. In PHP, variables do not need to be defined in advance and can be used directly. The type of the variable is automatically generated when assigning a value. The types of PHP variables are divided into: integer (int), double (double), string (string), array (array), and object (object).
When the integer size exceeds its range, it is automatically converted to double precision. The value range is as follows:
┌─────┬─────┬──────┬──── ────────┐
│ Declaration type │ Length (bits) │ Length (bytes) │ Value range │
├─────┼─────┼─── ───┼────────────┤
│ int │ 32 │ 4 │-2147483647~2147483647 │
├─────┼─────┼── ────┼────────────┤
│ double │ 32 │ 4 │ 1.7E-308~1.7E+308 │
└─────┴── ───┴──────┴────────────┘
String, usually represented by "" (double quotes). It can also be expressed with (single quotes), as follows:
$a="abc";
$b="abc$a";
$c=abc$a;
$d="" cde"";
$e="cde";
Various variables in PHP are distinguished by adding "$" before the variable name.
Note that the content of $b is abcabc, the content of $c is abc$a, the content of $d is "cde", and the content of $e is also "cde". It can be seen that the variable names in the content in double quotes will be replaced, but those in single quotes will not. The content in double quotation marks needs to be escaped, such as $, which should be represented by $, but the content in single quotation marks should not be escaped.


The array syntax in PHP is:
Array name [index]
The index can be a number or a text. But it is not recommended to use text because it does not make much sense. It is also more flexible than other languages ​​for arrays. For example:
$names[]=100;
$names[]=200;
$names[]="hi,how are you ";
$names[]=98.5;
$names[]=1.7E+23;
$num=count($names);
for ($i=0;$i echo "$names[$i]
";
}
?>
It can be seen that the elements in an array are not necessarily of the same type , this is the "live" part of PHP arrays.
Using objects makes it easier for programmers to maintain and makes programs more readable. Compared with other languages, PHP is much simpler. It only has categories, methods, attributes, extensions, etc.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531880.htmlTechArticleIn the article "Talk about HTML syntax", I have introduced the basic HTML syntax. It is possible to compile a static Web page, but it is very important to dynamically interact information. For example, the membership system of some websites will...
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