mirror of
https://github.com/php/php-src.git
synced 2026-03-24 08:12:21 +01:00
RFC: https://wiki.php.net/rfc/saner-array-sum-product Moreover, the internal fast_add_function() function was removed.
23 lines
433 B
PHP
23 lines
433 B
PHP
--TEST--
|
|
Test array_sum() function with objects castable to numeric type
|
|
--EXTENSIONS--
|
|
gmp
|
|
--FILE--
|
|
<?php
|
|
$input = [gmp_init(25), gmp_init(6)];
|
|
|
|
echo "array_sum() version:\n";
|
|
var_dump(array_sum($input));
|
|
|
|
echo "array_reduce() version:\n";
|
|
var_dump(array_reduce($input, fn($carry, $value) => $carry + $value, 0));
|
|
?>
|
|
--EXPECT--
|
|
array_sum() version:
|
|
int(31)
|
|
array_reduce() version:
|
|
object(GMP)#5 (1) {
|
|
["num"]=>
|
|
string(2) "31"
|
|
}
|