zoukankan      html  css  js  c++  java
  • array_count_values源码

    PHP_FUNCTION(array_count_values)
    {
        zval    *input,            /* Input array */
                **entry,        /* An entry in the input array */
                **tmp;
        HashTable *myht;
        HashPosition pos;
    
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &input) == FAILURE) {
            return;
        }
    
        /* Initialize return array */
        array_init(return_value);
    
        /* Go through input array and add values to the return array */
        myht = Z_ARRVAL_P(input);
        zend_hash_internal_pointer_reset_ex(myht, &pos);
        while (zend_hash_get_current_data_ex(myht, (void **)&entry, &pos) == SUCCESS) {
            if (Z_TYPE_PP(entry) == IS_LONG) {
                if (zend_hash_index_find(Z_ARRVAL_P(return_value), Z_LVAL_PP(entry), (void **)&tmp) == FAILURE) {
                    zval *data;
                    MAKE_STD_ZVAL(data);
                    ZVAL_LONG(data, 1);
                    zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_PP(entry), &data, sizeof(data), NULL);
                } else {
                    Z_LVAL_PP(tmp)++;
                }
            } else if (Z_TYPE_PP(entry) == IS_STRING) {
                if (zend_symtable_find(Z_ARRVAL_P(return_value), Z_STRVAL_PP(entry), Z_STRLEN_PP(entry) + 1, (void**)&tmp) == FAILURE) {
                    zval *data;
                    MAKE_STD_ZVAL(data);
                    ZVAL_LONG(data, 1);
                    zend_symtable_update(Z_ARRVAL_P(return_value), Z_STRVAL_PP(entry), Z_STRLEN_PP(entry) + 1, &data, sizeof(data), NULL);
                } else {
                    Z_LVAL_PP(tmp)++;
                }
            } else {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can only count STRING and INTEGER values!");
            }
    
            zend_hash_move_forward_ex(myht, &pos);
        }
    }

    记录该源码,等待后续的分析。

  • 相关阅读:
    ASP.NET MVC中防止跨站请求攻击(CSRF)
    C#操作JSON学习
    C# 产生随机密码
    博客园上好的技术系列收藏
    OWIN学习
    bzoj1068: [SCOI2007]压缩
    bzoj1012: [JSOI2008]最大数maxnumber
    bzoj1055: [HAOI2008]玩具取名
    bzoj1011: [HNOI2008]遥远的行星
    bzoj1008: [HNOI2008]越狱
  • 原文地址:https://www.cnblogs.com/minbbp/p/3580089.html
Copyright © 2011-2022 走看看