Released: ArrayLookup 1.7.0
1.7.0
Add new Collector
class, for collect filtered data, with new transformed each data found, for example, we have data:
$data = [
' a ',
' b ',
' c ',
new \stdClass(),
];
we need to collect new data into new array with transformed no space in results.
Before
$newArray = [];
foreach ($data as $datum) {
if (is_string($datum)) {
$newArray[] = trim($datum);
}
}
After, with Collector class
use ArrayLookup\Collector;
$when = fn (mixed $datum): bool => is_string($datum);
$limit = 2;
$transform = fn (string $datum): string => trim($datum);
$newArray = Collector::setUp($data)
->when($when)
->withLimit(2) // optional to only collect some data provided by limit config
->withTransform($transform)
->getResults(); // ['a', 'b', 'c']