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.
2018-08-29 05:00:15 +00:00
|
|
|
--TEST--
|
|
|
|
Test Collection::distinctBy().
|
|
|
|
--FILE--
|
|
|
|
<?php
|
|
|
|
$array = [];
|
|
|
|
for ($i = 0; $i < 100; ++$i) {
|
2018-09-12 05:50:26 +00:00
|
|
|
$array[] = random_bytes(mt_rand(1, 10));
|
2018-08-29 05:00:15 +00:00
|
|
|
}
|
|
|
|
$get_len = function ($value) {
|
|
|
|
return strlen($value);
|
|
|
|
};
|
|
|
|
$distinct = Collection::init($array)->distinctBy($get_len)->toArray();
|
|
|
|
$array1 = [];
|
|
|
|
$distinct_idx = array_keys(array_unique(array_map($get_len, $array)));
|
|
|
|
foreach ($distinct_idx as $idx) {
|
|
|
|
$array1[] = $array[$idx];
|
|
|
|
}
|
|
|
|
if ($distinct != $array1) {
|
2018-08-29 05:01:43 +00:00
|
|
|
echo 'Collection::distinctBy() failed.', PHP_EOL;
|
2018-08-29 05:00:15 +00:00
|
|
|
}
|
|
|
|
?>
|
|
|
|
--EXPECT--
|