PHP Basics _ PHP Tutorial

Source: Internet
Author: User
Tags php basics
PHP basic learning summary. Lexical Structure 1. in PHP, keywords, function names, and class names are case-insensitive, but variable names are case-sensitive. 2. semicolon, space, line feed, braces in PHP, points Lexical Structure
1. in PHP, keywords, function names, and class names are case-insensitive, but variable names are case-sensitive.
2. semicolons, spaces, line breaks, and braces are in PHP. semicolons indicate the end of a statement. Generally, spaces and line breaks are meaningless in PHP, but they can improve code readability. Braces indicate a statement block.
3. PHP annotations support multiple annotation methods. For example, the Shell annotation method (starting with #), the C language annotation method (starting with/*, ending with */), and the C ++ language annotation method (starting ). For example: 12345 # Shell comment/* C language comment * // C ++ language comment 4. direct volume refers to the data values that appear directly in the program, such as data and strings.
5. identifiers, variable names, function names, class names, and constant identifiers refer to names for variable names, function names, and class names. Its first letter is an underline and a lowercase letter (ASCII code 0x7F ~ 0xFF can also be used, but it is generally not used .), The first letter can contain underscores (_), upper and lower case letters (_), and numbers (0 ~ 9.
The variable name starts with a dollar sign ($) and is followed by an identifier. ※Variable names are case-sensitive function names and class names that are directly composed of identifiers. ※Php constants whose function names and class names are case insensitive are defined by define. For example, 1 define ('name', 'utuo ');
6. the main keywords include the following $ HTTP_COOKIE_VARS $ HTTP_ENV_VARS $ HTTP_GET_VARS $ HTTP_POST_FILES $ HTTP_POST_VARS...

PHP learning (2) Data types

PHP has eight data types.
There are four basic types: integer, floating point, string, and Boolean;
Two composite types: Array and object; two other types: Resource and NULL.
1. the integer type can be positive or negative. The general range is-2147483648 ~ 2147483647.
There are three writing methods: decimal, octal, and hexadecimal. It can use the is_int ($ x) function to test whether it is an integer.
Example: 12345678910
$ A = 10; // decimal
$ A =-10; // decimal
$ A = 010; // octal
$ A =-010; // octal
$ A = 0x10; // hexadecimal
$ A =-0x10; // hexadecimal
If (is_int ($ a) echo $ ;...

PHP learning (3) variables

In the previous article, we mentioned that the variable is an identifier prefixed with the dollar sign ($. For example, $ name. Variables can store any type of values. variables are declared without the displayed syntax in PHP. When you use a variable for the first time, the variable is created.
1. variable, that is, to store a variable name in another variable, for example, 12 $ name = 'value'; $ name = '2016'; after the variable is executed, creates a $ value variable whose value is '000000 ′. 2. variables are referenced in PHP, and the variables are similar to pointers. Variable reference indicates that two variables are directed to the same value. The alias is similar. Because it points to the same address, changing the value of one variable also changes. It should be noted that resetting a variable does not change another variable, because resetting a variable only points to NULL without modifying the value pointed to by another variable.
Function parameters and return values can all be referenced as variables, which can prevent copying large data types (such as strings, arrays, and classes ).
Sample code:
12345678910111213141516171819 // change the value of one of the variables
$ Value_a = 'test ';
$ Value_ B = & $ value_a;
$ Value_ B = 'change ';
Print "\ $ value_a is $ value_a ";
Print "\ $ value_ B is $ value_ B ";...

PHP learning (4) expressions and operators

A php expression is a statement that calculates the result using certain operators. PHP operators are basically derived from the C language and Perl language.
1. in implicit conversions to numeric computation (addition, subtraction, multiplication, division, and remainder), convert the string to a number first. if the converted number is a floating point or the expression contains a floating point, other digits are converted to floating point numbers for calculation. otherwise, integers are used for calculation. During string calculation (string connection), the number is converted into a string and then connected.
2. increment and decrease can be placed before or after a variable. Add (subtract) 1 before calculation, and then Add (subtract) 1 after the variable.
3. conversion operators include some synonymous operators. For example, (int), (integer), (float), (real), (bool), and (boolean). The following table lists the PHP operators, "priority" indicates the operator's priority from large to small (high priority). "associativity" indicates whether the operator is left or right ("none" indicates no combination ).
The concatenation operator 19 does not create the object 18 right [] array subscript 17 right !,~ Logic inversion, bitwise inversion right ++,-incrementing, descending right (int), (double), (string), (array), (object) type conversion right...

PHP learning (5) flow control statements

In PHP, a flow control statement consists of a conditional statement and a loop statement. Among them, the flow control statements include if/else and switch statements, and the loop statements include the while and for statements.
1. in PHP, IF statements have two syntax structures. One is to use braces to represent statement blocks, and the other is to use colons to represent statement blocks. The former is generally used in pure code, while the latter is generally used in combination with HTML. The statement block if ($ value) {// operation;} elseif ($ value) {// operation ;} else {// operation;} // colon indicates the statement block if ($ value): // operation; elseif ($ value): // operation; else: // operation; endif ;...

PHP learning (6) Includes code and embedded PHP

The code is included in PHP. the code contains four functions, including include_once require require_once.
The main difference between include and require is that if the file does not exist, The require function will throw a fatal error, while the include function will only throw a warning.
Include include_once and require require_once, where the suffix "once" indicates that if the code already contains the file, the file will not be referenced again. There are four ways to embed PHP into HTML: XML, SGML, ASP, and script. ASP is not supported by default. you must modify asp_tags to On in the PHP configuration file [PHP. ini.
Sample code for the four methods: 123456789101112 // XML format
Echo 'Hello, world ';
?>
// SGML format
Echo 'Hello, world ';
?> // ASP format
<%
Echo 'Hello, world ';
%>
// Script format

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: info-contact@alibabacloud.com 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.