This article mainly introduces about the PHP source code ten: About the Array_keys,array_values function, has a certain reference value, now share to everyone, the need for friends can refer to
The first article of the New Year, first of all to friends
Today is free to read the code, write something, stay as a souvenir!
Array Array_keys (array input [, mixed search_value [, BOOL strict]])
Array_keys () returns the key name of the number or string in the input array.
If an optional parameter, Search_value, is specified, only the key name of the value is returned. Otherwise all the key names in the input array will be returned. Since PHP 5, the strict parameter can be used to compare the same (= = =).
Implementation of the Array_keys function in line 2416 of the standard/array.c file Php_function (Array_keys)
The program in accordance with the usual PHP style, the first to determine whether the input is correct, if there is a third parameter, then the size of the function to use Is_identical_function (by default, the use of the Is_equal_function function)
Then initialize the returned array, iterate over the given array, take each element's key value, assign to the returned array, the key value is divided into numbers and string two, the most important function is the hash operation function Zend_hash_get_current_key_ Ex (takes the key value of the current element)
Zend_api int zend_hash_get_current_key_ex (HashTable *ht, char **str_index, uint *str_length, ulong *num_index, Zend_bool Duplicate, hashposition *pos) { Bucket *p; p = pos? (*pos): ht->pinternalpointer; Is_consistent (HT); if (p) { if (p->nkeylength) { // numeric nkeylength length is 0 if (duplicate) { *str_index = Estrndup (P- >arkey, p->nkeylength-1); } else { *str_index = p->arkey; /* Arkey store Key Name (key of string type) must be the last member, * /} if (str_length) { *str_length = p->nkeylength; } return hash_key_is_string; } else { *num_index = p->h; Store numeric KEY value return hash_key_is_long; } } return hash_key_non_existant;}
The understanding of this function is primarily the understanding of the bucket definition
For bucket-related content, please visit http://www.php.cn/php-weizijiaocheng-405316.html
Array array_values (array input)
Array_values () returns all the values in the input array and establishes a numeric index on them.
The Array_values function is basically similar to the function implementation of Array_keys, and there is a zend_hash_get_current_key_ex operation and a judgment value type.
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!