PHP_FUNCTION(array_count_values)
{
zval *input, /* Input array */
*entry, /* An entry in the input array */
*tmp;
HashTable *myht; if (zend_parse_parameters(ZEND_NUM_ARGS(), "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_FOREACH_VAL(myht, entry) {
ZVAL_DEREF(entry);
/* 数组元素的值只能是字符串或整数 */
if (Z_TYPE_P(entry) == IS_LONG) { // 数组元素值为整数
if ((tmp = zend_hash_index_find(Z_ARRVAL_P(return_value), Z_LVAL_P(entry))) == NULL) { // 返回数组中不存在该键
zval data;
ZVAL_LONG(&data, ); // 首次出现,+1
zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_P(entry), &data); // 添加到返回值数组
} else {
Z_LVAL_P(tmp)++; // 元素值出现次数+1
}
} else if (Z_TYPE_P(entry) == IS_STRING) { // 数组元素值为字符串
if ((tmp = zend_symtable_find(Z_ARRVAL_P(return_value), Z_STR_P(entry))) == NULL) {
zval data;
ZVAL_LONG(&data, );
zend_symtable_update(Z_ARRVAL_P(return_value), Z_STR_P(entry), &data);
} else {
Z_LVAL_P(tmp)++;
}
} else {
// 数组元素的值非字符串或整数,则报warning错误。
php_error_docref(NULL, E_WARNING, "Can only count STRING and INTEGER values!");
}
} ZEND_HASH_FOREACH_END();
}

php内置函数分析array_count_values()的更多相关文章

  1. map内置函数分析所得到的思路

    map:会根据提供的函数对指定序列做映射. map(func, *iterables) --> map object Make an iterator that computes the fun ...

  2. php内置函数分析之array_diff_assoc()

    static void php_array_diff_key(INTERNAL_FUNCTION_PARAMETERS, int data_compare_type) /* {{{ */ { uint ...

  3. php内置函数分析之array_combine()

    PHP_FUNCTION(array_combine) { HashTable *values, *keys; uint32_t pos_values = ; zval *entry_keys, *e ...

  4. php内置函数分析之ucwords()

    PHP_FUNCTION(ucwords) { zend_string *str; char *delims = " \t\r\n\f\v"; register char *r, ...

  5. php内置函数分析之strtoupper()、strtolower()

    strtoupper(): PHP_FUNCTION(strtoupper) { zend_string *str; ZEND_PARSE_PARAMETERS_START(, ) Z_PARAM_S ...

  6. php内置函数分析之ucfirst()、lcfirst()

    ucfirst($str) 将 str 的首字符(如果首字符是字母)转换为大写字母,并返回这个字符串. 源码位于 ext/standard/string.c /* {{{ php_ucfirst Up ...

  7. php内置函数分析之trim()

    官方手册中: 类似函数还有两个:ltrim() 和 rtrim().分别处理字符串的左侧.右侧. trim()的具体实现位于:ext/standard/string.c /* {{{ proto st ...

  8. php内置函数分析之str_pad()

    PHP_FUNCTION(str_pad) { /* Input arguments */ zend_string *input; /* Input string 输入字符串*/ zend_long ...

  9. php内置函数分析之array_fill_keys()

    PHP_FUNCTION(array_fill_keys) { zval *keys, *val, *entry; if (zend_parse_parameters(ZEND_NUM_ARGS(), ...

随机推荐

  1. Linux_Comand - Check disk space

    df -h du -sh Delete folder older than 30 days find /path -name "test-*" -type d -mtime +30 ...

  2. 各种sort排序总结

    冒泡排序 选择排序 插入排序

  3. serial redirection

    int setOption(int fd,int nSpeed, int nBits, char mode,char nEvent, int nStop) { struct termios newti ...

  4. 怎么用jira写bug

    工具/原料 有网的电脑 方法/步骤1: 打开公司给的访问JIRA的链接,输入公司给你注册的账号和密码,点击登录 方法/步骤2: 点击JIRA主菜单上的“创建”,进入编辑bug界面 方法/步骤3: 项目 ...

  5. vs2010 setup 打包 安装 BAT批处理实现自动安装软件功能

    CLS@echo offECHO.ECHO 安装 Diskeeper 7.0.428ECHO 请稍等...start /wait %systemdrive%\install\Applications\ ...

  6. CentOS6.5 编译安装PHP5.6(apache模块)

    一.环境准备 1. 下载php源码包 # wget http://cn2.php.net/distributions/php-5.6.30.tar.gz # tar -xf php-5.6.30.ta ...

  7. C语言Ⅰ博客作业01

    1.你对计算机科学与技术专业了解是怎样? 本专业培养具有良好的科学素养,系统地.较好地掌握计算机科学与技术包括计算机硬件.软件与应用的基本理论.基本知识和基本技能与方法,能在科研部门.教育单位.企业. ...

  8. 【转】MySQL查询缓存详解

    [转]MySQL查询缓存详解 转自:https://www.cnblogs.com/Alight/p/3981999.html 相关文章:http://www.zsythink.net/archive ...

  9. MySQL-快速入门(6)连接查询、子查询、正则表达式查询、数据的插入删除更新

    1.内连接查询:inner join ... on 只有满足条件的记录才能够出现在结果关系中,即完全相等.自连接查询是一种特殊的内连接查询. 2.外连接查询: 1>左外连接 / 左连接:返回包括 ...

  10. 为何单片机程序不用加载到RAM

    一. STM32程序构成 1.1. STM32的存储空间 1.1.1. RAM 1.1.1.1 单片机的RAM是SRAM. 1.1.1.2. SRAM特点 a.优点,速度快,不必配合内存刷新电路,可提 ...