[RFC] array_only() and array_except() – Utility fu nctions for array key filtering
| From: | Muhammed Arshid KV | Date: | Fri, 20 Feb 2026 09:25:53 +0000 |
| Subject: | [RFC] array_only() and array_except() – Utility fu nctions for array key filtering | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-130102@lists.php.net to get a copy of this message | ||
Hello Internals,
I would like to propose a new RFC titled *array_only() and array_except()*.
RFC: https://wiki.php.net/rfc/array_only_except
<https://wiki.php.net/rfc/array_only_except?utm_source=chatgpt.com>
This RFC proposes adding two utility functions to the PHP core:
• array_only(array $array, array $keys): array
• array_except(array $array, array $keys): array
These functions allow selecting or excluding specific keys from an array.
Similar helpers are commonly used in frameworks, and adding native support
would improve readability and consistency in userland code.
Summary:
• array_only() returns a new array containing only the specified keys.
• array_except() returns a new array excluding the specified keys.
• Original array is not modified.
• Works with associative and numeric keys.
• No impact on SAPIs or on OPcache.
I would appreciate feedback and suggestions from the community.
If there is general agreement, I plan to move the RFC forward.
Thanks,
Muhammed Arshid KV