PHP: Special Syntax Record_PHP Tutorial

WBOY
Release: 2016-07-13 17:47:19
Original
868 people have browsed it

Most of the syntax of PHP is very similar to that of interpreted syntax such as ASP, but there are still some subtle differences. In the process of becoming familiar with PHP syntax, the relevant differences are recorded here as notes.

1. Concatenation operator

In PHP, there is only one string operator.

The concatenation operator (.) is used to concatenate two string values.

To concatenate two variables, use the dot operator (.):

The code is as above. In other languages, this is usually a "+", and the function of "." here is equivalent to "+"

2. Associative array

An associative array in which each ID key is associated with a value.

Using numeric arrays is not the best practice when storing data about specifically named values.

With associative arrays, we can use values ​​as keys and assign values ​​to them.

Associated numbers are actually similar to hashtable

The following are two creation methods:

$ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34);

$ages['Peter'] = "32"; $ages['Quagmire'] = "30"; $ages['Joe'] = "34";

Through the above example, we can also understand the "=>" assignment operator

3. Variable variables

The name of a variable can be changed dynamically.

$test_1 = 5; $test_2 = test_1; $$test_2 = 10; echo $test_1;

4. Reference operator

Reference operator: "&" The reference is equivalent to an alias, not a pointer. Points to the same address in memory.

5. Error suppression operator: @

6. Execution operator:

The execution operator is: ". Used to execute commands. For example:

$cmdtest = `dir c:`;

echo $cmdtest;

7. Type operator:

Type operator: instanceof. Checks whether an object is an instance of a specific class.

----------------------------------------

Please indicate the source when reprinting: CNZQS|JesseZhang’s personal blog - "php: Special Grammar Record"

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478534.htmlTechArticleMost of the syntax of php is very similar to that of asp and other interpreted syntax, but there are still some subtle differences. , in the process of becoming familiar with PHP syntax, here are the relevant differences recorded as a pen...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template