In PHP, variable names and variable values correspond to Zval, zend_value, variable memory is managed by reference count, PHP7 the reference count is transferred to value, the transfer assignment between variables is also for Zend_value
PHP7 the Boolean type directly into True, false, two types, which are separated directly by type types and therefore do not require specific value.
The string in PHP does not pass the char type, but through the zend_string result, zend_value points to the specific structure through STR, zend_string in addition to the string content, there are other specific information:
GC: Reference count information for variables, for memory management
H: Strings are hashcode by time33 algorithm,
Len: Length of string
Val: The contents of the string
Special: Storing the contents of the string with a variable array, variable-length structure can not only save a memory allocation, but also help memory management, free when the zend_string can be released directly, it is important to note that the end of the storage string will have a end of the rich ""
The bottom of the array is a hash table, which is directly accessed according to Key-value data structure, its key-value exists mapping function, that is, according to key through the mapping function directly indexed to the corresponding value value, that is, by key directly mapped into memory, This speeds up the search speed and ideally allows you to know the unknown origin keyword directly.
The structure of Buckey is simple, that is, key and value, if the element is a numeric index, then its value is the value of the numeric index, if the element is a string, then its key is the hash value obtained through time33.
The basic implementation of the array: the hash table mainly consists of two parts, the storage element array, the hash function, a simple hash function is through the mode, such as the size of the hash table is 8, then the hash list initialization element when the array is allocated 8 element size space, The value given by the hashcode of key and the 8 modulo is the subscript of the element, so that it can be mapped to the exact location of the storage array by key. The problem with this implementation is that the element's position in the array is random, unordered, the PHP array is ordered, and in order for the hash list to be ordered, the hash table in PHP adds a layer of mapping between the hash function and the element array, which is an array of the same size as the array of the stored elements. Its storage element is integer, which holds the subscript for the actual stored ordered array, the elements are inserted into the actual storage array one at a time, and then the array subscript is stored in the newly added mapping table in the location listed by the hash function.
This is the underlying implementation of the array, but one problem is the hash conflict, because Time33 ($key)%size may get the same value, the solution is to string the conflicting buckets into a linked list. It is important to note that the old ones are placed in the list and replaced with the new ones.
The lookup process: first calculates the hashcode and the hash value according to the key, then obtains from the intermediate mapping table according to the hash value the storage element in the orderly storage element's position idx, then extracts the bucket from the ordered village coarse array according to the IDX, finally from takes out the bucket to see I ah loris I traversal, Determine if the bucket key is the key to look for, if it is to stop the traversal, otherwise continue according to Zend.u2.next (used to store the conflict above I said the old) traversal comparison.
Expansion: PHP array to achieve automatic expansion, the insertion will first check whether the free space, when the discovery of space is full no place to accommodate the new element will trigger the expansion logic, the expansion after the insertion.
Reference: When using references to arrays, it is important to note that references can only be generated by & and cannot be passed by assignment, except that the PHP reference is only one level.
PHP data type