Some Notes on PHP references and symbols
PHP references and symbols are difficult to grasp. New users are writingCodePay more attention to this point, because if you have a wrong understanding of the use of PHP references and symbols, it will lead to errors in the entire code you have written.
How to Use PHP to associate an array Query Result
PHP Common Errors
PHP function header () queries the specific solution of a single part ..
PHP array to string and PHP string to array... many people misunderstand that the reference in PHP is the same as the pointer in C. In fact, this is not the case and it is quite different. In C language, pointers do not need to be explicitly declared in the array transfer process, but must be defined by *. in PHP (
Similar to pointer) the function is not implemented by the user, but implemented by the Zend core. The PHP reference and symbol adopts the principle of "Copy at write time", that is, unless a write operation occurs, variables or objects pointing to the same address are not copied, for example, the following code:
$ A = array ('A', 'c'... 'n'); $ B = $ A; ifProgramRun it only here. $ B and $ B are the same, but they do not use different memory spaces like C. Instead, $ A and $ B point to the same memory, this is the difference between PHP and C. It does not need to be written as $ B = & $ A to indicate that $ B points to the memory of $ A. Zend
Zend has helped you implement the reference, and it will be very intelligent to help you determine when to handle this and when not.
If you continue to write the following code later, add a function, pass the parameter through PHP Reference & symbol, and print the output array size.
Function printarray (& $ ARR) // pass the reference {print (count ($ ARR);} printarray ($ A); in the above Code, we passed the $ A array to the printarray () function through the PHP Reference & Symbol. The Zend engine will think that printarray () may cause changes to $.
A $ A data copy is automatically produced for $ B, and a memory is re-applied for storage. This is the "Copy at write time" concept mentioned above.
If we change the above Code to the following:
Function printarray ($ ARR) // value transfer {print (count ($ ARR);} printarray ($ );
The above Code directly transmits the $ a value to printarray (). At this time, there is no reference transfer, so there is no copy at write time.
You can test the execution efficiency of the above two lines of code, for example, adding a loop 1000 times outside to check the running time, the result will let you know that improper use of PHP references and symbols will lead to a performance reduction of more than 30%.