This repository has been archived on 2020-03-30. You can view files and clone it, but cannot push or open issues or pull requests.
ext-collections/tests/039-reduce.phpt

17 lines
461 B
PHP

--TEST--
Test Collection::reduce() and Collection::reduceRight().
--FILE--
<?php
$collection = Collection::init(['a', 'b', 'c', 'd', 'e']);
$reduce_cb = function ($acc, $value, $key) {
return $acc.$value.strval($key);
};
if ($collection->reduce($reduce_cb) != 'ab1c2d3e4') {
echo 'Collection::reduce() failed.', PHP_EOL;
}
if ($collection->reduceRight($reduce_cb) != 'ed3c2b1a0') {
echo 'Collection::reduceRight() failed.', PHP_EOL;
}
?>
--EXPECT--