Home > Article > Backend Development > PHP: Special Syntax Record_PHP Tutorial
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"