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/029-remove-retain-while.phpt

23 lines
618 B
PHP

--TEST--
Test Collection::removeWhile() and Collection::retainWhile().
--FILE--
<?php
$array = ['a' => 4, 'b' => 1, 'c' => 9, 'd' => -2, 'e' => 0];
$pred_is_odd = function ($value) {
return $value % 2;
};
$collection = Collection::init($array);
$collection->removeWhile($pred_is_odd);
if ($collection->toArray() != ['a' => 4, 'd' => -2, 'e' => 0]) {
echo 'Collection::removeWhile() failed.', PHP_EOL;
}
$collection = Collection::init($array);
$collection->retainWhile($pred_is_odd);
if ($collection->toArray() != ['b' => 1, 'c' => 9]) {
echo 'Collection::retainWhile() failed.', PHP_EOL;
}
?>
--EXPECT--