PHP Basic Learning Summary _php Foundation

Source: Internet
Author: User
Tags arrays constant function definition lowercase php programming variable scope
Lexical structure
1. Capitalization in PHP, keyword, function name, and class name are case-insensitive, but variable names are case-sensitive.
2. Semicolons, spaces, wrapping, curly braces in PHP, semicolons represent the end of a statement. In general, whitespace and line wrapping have no real meaning in PHP, but they can improve the readability of your code. Curly braces represent a block of statements.
3. Note PHP supports a variety of annotation methods. such as Shell annotation Way (beginning with #), C language annotation (starting with///ending), C + + language annotation (beginning with//). such as: 12345 # Shell Annotation Mode/* C language Annotation mode *///C + + language annotation way 4. A direct measure of a data value, such as data or a string, that appears directly in a program.
5. Identifiers, variable names, function names, class names, and constant identifiers are names that are named for variable names, function names, and class names. Its initials are underlined and uppercase and lowercase (ASCII 0x7f~0xff can also be used, but generally no one uses it.) , the initials can be made up of underscores, uppercase and lowercase letters, and digital 0~9.
The variable name begins with a dollar sign ($) followed by an identifier. ※ variable names are case-sensitive function names and class names are directly composed of identifiers. ※ The function name and the class name are not case-sensitive PHP constants are define to define. such as 1 define (' NAME ', ' Yutuo ');
6. Key keywords have the following $HTTP _cookie_vars $HTTP _env_vars $HTTP _get_vars $HTTP _post_files $HTTP _post_vars ...

PHP Learning (2) data types

PHP has 8 types of data.
Four basic types: shaping, floating-point, string, and Boolean;
Two types of composite: arrays and objects, two other types: resources and NULL.
1. Plastic shaping is an integer that can have positive or negative. The usual range is:-2147483648 ~ 2147483647.
There are three kinds of writing: decimal, octal, and hexadecimal. It can use function Is_int ($x) to test whether it is an integer.
such as: 12345678910
$a = 10; Decimal
$a =-10; Decimal
$a = 010; Octal
$a =-010; Octal
$a = 0x10; Hexadecimal
$a = -0x10; Hexadecimal
if (Is_int ($a)) echo $a; ...

PHP Learning (3) variables

In the previous article, we said that the variable is a dollar sign ($) as the prefix identifier. such as: $name. A variable can hold any type of value, and the syntax that is not displayed in PHP declares the variable. When you use a variable for the first time, the variable is created.
1. Variable variable variables, that is, a variable name exists in another variable, such as: $name = ' value '; $ $name = ' 1234 '; After execution, a $value variable is created, and its value is ' 1234′. 2. Variable reference in PHP, the variable is the same as the pointer. A variable reference indicates that two variables are pointed to the same value, and the alias meaning is pretty much the same. Because it points to the same address, you change the value of one of the variables, and the other variable changes. Note that resetting a variable does not change another variable, because resetting the variable simply points the variable to null without modifying the value that the other variable points to.
The parameters of a function, and the return value, can be a variable reference, which prevents large data types such as strings, arrays, and classes from being replicated.
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 a result by a certain operator. PHP's operators are basically from the C language and Perl language for reference.
1. Implicit type conversion numeric calculation (plus, subtract, multiply, divide, seek remainder etc.), first converts a string into a number, if the number is converted to floating-point numbers or expressions containing floating point number, then other numbers are converted to float to calculate, otherwise use integer to calculate. String computation (string concatenation), converts a number to a string and then joins.
2. Incremental and descending increments and decrements can be placed before a variable or after a variable. Put in the variable before the first plus (minus) 1 before the calculation, placed in the variable after the first calculation plus (minus) 1
3. Type conversion operators have some synonymous operators. For example: (int) and (integer), (float) and (real), (bool) and (Boolean): The following table lists the operators of PHP, where "priority" from large to small (high precedence) represents the precedence of the operator; "Associativity" Indicates whether the operator is a left or right combination ("No" means no associativity).
Precedence associativity operator Description 19 No new Create object 18 right [] array subscript 17 Right! , ~ logical reverse, anti-rightist ++,– increments, descending right (int), (double), (string), (array), (object) type conversion right ...

PHP Learning (5) Flow control statements

In PHP, flow control statements are mainly composed of conditional statements and circular statements. Where the flow control statement has if/else and switch statements, the LOOP statement has a while and a for statement.
1. If statement in PHP, the IF statement has two grammatical structures. A statement block is represented by a brace, and a colon is used to represent a statement block. The former is typically used in pure code, which is typically used when code and HTML are combined. The two types of writing are as follows: 1234567891011121314151617//curly braces denote statement block if ($value) {//operation;} elseif ($value) {//operation;} else {//action;}//colon denotes statement block if ($value)://operation; ElseIf ($value)://operation; ELSE://operation; endif ...

PHP Learning (6) contains code and embeds PHP

Contains code in PHP, contains four functions, include include_once require require_once.
The main difference between include and require is that if the file does not exist the Require function throws a fatal error, and the include only throws a warning.
Include include_once and require require_once, where the suffix is once means that if the code already contains the file, it is no longer referenced. Embedded PHP has four ways to embed PHP in HTML: XML form, SGML form, ASP form, script form. The ASP form is not supported by default and must be modified in the PHP configuration file [php.ini] to Asp_tags.
The four methods sample code are as follows: 123456789101112//XML form
<?php
Echo ' Hello, world ';
?>
SGML Form
?
Echo ' Hello, world ';
?>//ASP form
<%
Echo ' Hello, world ';
%>
Script form
<script language= "PHP" > Echo ...

PHP Learning (7) function

This article describes the invocation of functions, definitions, parameters, and return values.
1. Function call in PHP, directly with the function name plus parameters can call functions, basically a little basic people can understand. such as: 1234 $value = Test (1); function test ($value) {return $value + +;}
2. Function definition said in the PHP learning (1) lexical structure "identifier refers to the name of the variable name, function name and class name." Its initials are underlined and uppercase and lowercase (ASCII 0x7f~0xff can also be used, but generally no one uses it.) , the initials can be made up of underscores, uppercase and lowercase letters, and digital 0~9. The function name is made up of identifiers. Because PHP does not support function overloading, the function name cannot have duplicate names. In addition, the function can be nested declarations, but not very useful. Nested declared functions cannot call the inner function when the outer function is not called. As in the following code, an exception will occur if the inner function is called individually. 12345678 echo Outter (); echo inner (); function Outter () {function inner () {return 2;} return 1;}
3. Variable scope ...

PHP Learning (8) Reference string constants

In PHP, there are three ways to define a string constant. Single quotes, double quotes, and here documents from the UNIX shell.

Before introducing the three definition methods, a variable conversion is introduced first. In PHP, double quotes, and the here document definition from the Unix shell, convert the string's variable to the value of the variable. The variables of the font string can also be enclosed in braces {} to show the obvious.
Note that there is no variable conversion in the single quote string.
The following code:
Copy Code code as follows:

$name = ' Yutuo ';
Single quote string
Echo ' My name is $name ';
Single quote string
echo "My name is $name";
echo "My name is {$name}";
Here document string
Echo <<< End
My name is $name
My name is {$name}
End

The result is that (the output does not have any line wrapping, and in order to be easy to understand, I change the line in the result):
My name is $name
My name is Yutuo
My name is Yutuo
My name is Yutuo
My name is Yutuo

Here are three definitions for single quotes, double quotes, and here documents from the UNIX shell.

1. Single quote string
A single quote string refers to a string enclosed in single quotes. It supports only two escape characters, backslashes (\), and single quotes ('), which are represented by (\) and (\) respectively.
Note that the single quote string does not support (\ n) This wrapping, but single quote strings can be defined across rows. The following code:

Echo ' My name is Yutuo.
I am studing PHP. ';

The result is (the output has a newline):
The My name is Yutuo.
I am studing PHP.

2. Double quote string
A double quote string refers to a string enclosed in double quotes. It supports only a variety of escape characters, or it can be defined across rows. The book says there are curly braces and brackets, but I'm not PHP5.3.1 under the test. The escape character list for its sub-branches is as follows:

\ "Double Quotes
\ n Line Change
\ r Carriage Return
\ t tab
\ reverse Slash
\$ Dollar character
\000~777 octal ASCII code
\X00~FF hexadecimal ASCII code
3. Here document
Here documents make it easy to put multiple lines of text into a program. In addition to defining a method differently, its escape character and cross row definition and double quote string are exactly the same.
The method is defined as a <<< identifier and ends with a single line identifier. Note that there is a space between the <<< and the identifier, and no spaces before the end identifier.
The reference code can look at the front.

Resources:
PHP Programming, 2003, fourth string, reference string constant

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.