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. SSH port forwarding: bind: Cannot assign requested address

    https://www.electricmonk.nl/log/2014/09/24/ssh-port-forwarding-bind-cannot-assign-requested-address/

  2. 为什么在vmware中不能使用ctrl+alt+F1~6切换到字符控制台

    为什么在vmware中不能使用ctrl+alt+F1~6切换到字符控制台 是因为vmware虚拟机的快捷键: ctrl+alt也用到了 因为vmware本身的hot keys也用到了ctrl+alt: ...

  3. 在SOUI3.0中使用数值动画

    上一篇介绍了插值动画,插值动画是直接作用于窗口对象的. 数值动画则可以作用于任何对象. SOUI内置了3种数值类型的动画,分别是SIntAnimator, SFloatAnimator, SColor ...

  4. LeetCode.876-链表的中间节点(Middle of the Linked List)

    这是悦乐书的第337次更新,第361篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第206题(顺位题号是876).给定具有头节点的非空单链表,返回链表的中间节点.如果有两 ...

  5. vim加脚本注释和文本加密

    vim /etc/vimrc 一.李导版本 autocmd BufNewFile *.py,*.cc,*.sh,*.java exec ":call SetTitle()" fun ...

  6. 修改jupyter notebook默认路径,亲测

    anaconda环境 任务栏中找到anaconda/jupyter notebook,鼠标右键属性 点击确认即可.

  7. 国家授时中心的NTP服务器地址 210.72.145.44

    国家授时中心的NTP服务器地址 210.72.145.44

  8. 20191118 Spring Boot官方文档学习(4.9)

    4.9.安全 如果Spring Security在类路径上,则默认情况下Web应用程序是采用的.Spring Boot依靠Spring Security的内容协商策略来确定使用httpBasic还是f ...

  9. SpringBoot项目启动时执行初始化操作

    SpringBooot中的CommandLineRunner接口会在所有Spring Beans初始化之后,SpringApplication.run()之前执行. 1.添加pom引用 <?xm ...

  10. 关于Logcat

    1 android logcat api Log.i(String tag, String msg) info,普通信息 Log.d(String tag, String msg) debug,调试信 ...