PHP_FUNCTION(array_sum)
{
zval *input,
*entry,
entry_n; if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &input) == FAILURE) {
return;
} // 初始化返回值
ZVAL_LONG(return_value, ); // 循环取数组元素(entry)
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(input), entry) {
// 跳过数组和对象
if (Z_TYPE_P(entry) == IS_ARRAY || Z_TYPE_P(entry) == IS_OBJECT) {
continue;
}
// 数组元素复制
ZVAL_COPY(&entry_n, entry);
// 数组元素转为数字
convert_scalar_to_number(&entry_n);
// 数组元素累加
fast_add_function(return_value, return_value, &entry_n);
} ZEND_HASH_FOREACH_END();
}

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

  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. zabbix 监控hp 打印机

    https://share.zabbix.com/search?searchword=hp+printer&search_cat=1

  2. SpringBoot(十二):SpringBoot整合Kafka

    https://blog.csdn.net/saytime/article/details/79950635

  3. 杂项-PIN:百科

    ylbtech-杂项-PIN:百科 个人身份识别码(英语:Personal identification number,缩写为 PIN),又译为用户个人识别号码,常被称为PIN码(PIN number ...

  4. set_option()函数

    这个函数用于设置dataframe的输出显示, import pandas as ps pd.set_option('expand_frame_repr', True) # True就是可以换行显示. ...

  5. multiple datasource config

    Hi Harshit S. project structure: multiple datasource config as follows: step 1: step 2:add a datasou ...

  6. mysql5.6修改密码并授权所有远程用户可登陆

    1.my.ini文件,删除最后一行的"skip-grant-tables 2.执行"use mysql;",使用mysql数据库; 3.执行:update mysql.u ...

  7. JAVA日期时间相关库

    Java的日期时间库比较乱,同样一个Date在java.sql下定义,同时也在java.util下也定义了一遍,真不知道SUN是怎么想的. java8以后,java通过jsr310标准引入了一套符合I ...

  8. Docker网络大揭秘(单机)

    docker网络官网 https://docs.docker.com/network/ Docker容器和服务如此强大的原因之一是您可以将它们连接在一起,或将它们连接到非Docker工作负载.Dock ...

  9. 循环Gray码的生成(非递归)

    #!/usr/bin/env python #coding:utf-8 import sys def gray_code(n): if n < 1: return [] n += 1 array ...

  10. 题解 AT1877 【回文分割】

    题意:给定一个字符串 s,将 s 分割成一些子串,使每个子串都是回文串. 返回 s 所有可能的分割方案. 示例: 输入:aab 输出:3 解释:aba 思路: 记录字符串中每个字符出现的次数si 如果 ...