-
Couldn't load subscription status.
- Fork 0
Open
Labels
Description
TL;DR
Performance: array_column is faster, leveraging PHP’s internal C implementation.
Readability: array_column is more concise and direct.
From
/**
* @return string[]|array<int, string>
*/
public static function values(): array
{
return array_map(
static fn (self $operator): string => $operator->value,
self::cases()
);
}
To
/**
* @return string[]|array<int, string>
*/
public static function values(): array
{
return array_column(self::cases(), 'value');
}
array_map itself is implemented in C, but when combined with a custom closure, the closure introduces additional overhead because it executes PHP userland code for each element in the array.
array_column operates entirely within the optimized C layer, extracting values without requiring userland function calls, making it faster for this specific use case.