- var_dump: documentation ( source)
- array_reduce: documentation ( source)
- str_repeat: documentation ( source)
- range: documentation ( source)
- str_starts_with: documentation ( source)
<?php
$original = [];
foreach (range(1, 20_000) as $iteration) {
$original[] = [
'id' => str_repeat("{$iteration}.", 4),
'name' => 'name',
];
}
var_dump(
array_reduce(
$original,
static function (array $result, array $item): array {
if (str_starts_with($item['id'], '11')) {
$result[] = "{$item['id']}#{$item['name']}";
}
return $result;
},
[]
)
);
This script was stopped while abusing our resources