Re: [RFC] Four Pragmatic Directions for PHP: Simplicity, Arrays, Performance, Concurrency
| From: | Morgan | Date: | Tue, 24 Mar 2026 11:38:25 +0000 |
| Subject: | Re: [RFC] Four Pragmatic Directions for PHP: Simplicity, Arrays, Performance, Concurrency | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-130428@lists.php.net to get a copy of this message | ||
On 2026-03-24 23:08, 沉默领域、 wrote:
// Proposed $names = array_pluck($users, 'name'); $names = array_where($users, fn($u) => $u->active); $first = array_first($users); $grouped = array_group_by($users, 'role'); $compact = array_compact($data);Of those, array_compact() is obscure in its purpose, and of the others one exists under the suggested name and three of the others exist under different names. array_group_by() is the only one that isn't already implemented. I think it means: $roles = array_unique(array_column($users, 'role')); $grouped = array_combine($roles, array_map(fn($r) => array_filter($users, fn($u) => $u['role']==$r), $roles)); though there are more efficient (and readable) ways of doing that. -- Optimising the implementation would be more difficult if the language were allowed to be sloppier. Conversely, tightening up the language allows improved optimisation.