This article mainly introduces about the PHP source code 16: About the Array_count_values function, has a certain reference value, now share to everyone, the need for friends can refer to
Talking about PHP source code 16: About Array_count_values function
Array_count_values
(PHP 4, PHP 5)
array_count_values-the number of occurrences of all values in the statistics array
Description
Array array_count_values (array input)
Array_count_values () returns an array that uses the value in the input array as the key name, and the number of occurrences in the input array as the value.
SOURCE Program Description:
A two-sentence comment in the source code illustrates the implementation of this function
/* Initialize return array * /Array_init (return_value); /* Go through input array and add values to the return array */
But there are some details to note:
1. This function only recognizes strings and numbers, so a statement similar to the following is used in the program
if (z_type_pp (entry) = = Is_long) {} else if (z_type_pp (entry) = = is_string) {} else {php_error_docref (NULL tsrmls_cc, E_warning, "Can only count STRING and INTEGER values!");}
2, in the process of traversal, first of all to determine whether there is no, this process of judgment in the case of strings and numbers are also different, but ultimately for the hash table operation
The initialization for Zval in code is using the macro Zval *data; Make_std_zval (data);
The definition of tracking this macro is as follows:
Make_std_zval (data);==> #define MAKE_STD_ZVAL (ZV) \ zend.h 586 rows alloc_zval (ZV); \ Init_pzval (zv ); ==> #define ALLOC_ZVAL (z) \ Zend_fast_alloc (z, Zval, zval_cache_list) zend_alloc.h 165 rows ==> #define Zend_fast_alloc (P, type, fc_type) \ (p) = (type *) emalloc (sizeof (type)) zend_alloc.h 152 Rows ==> # Define EMALLOC (size) _emalloc ((size) zend_file_line_cc zend_file_line_empty_cc) zend_alloc.h 56 rows ==> Zend_api void *_emalloc (size_t size zend_file_line_dc zend_file_line_orig_dc) zend_alloc.c 2288-line program implementation ==> #define INIT_PZVAL (z) \ zend.h 576 lines (z)->refcount = 1; \ (z)->is_ref = 0;
Eof
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!