[PHP-DEV] [RFC] [Discussion] array_match

[email protected] (سپهر محمودی)
Newsgroups php.internals
Message-ID <CA+Jcf5tdhtK1SrXx6EBLCdmNdoBF1vMr0dTQou=ypLqPyq_-kQ@mail.gmail.com>
Hi everyone,

As some of you may know, my previous RFC (`array_search_range`) faced
significant opposition and feedback. I have listened to the community and
officially withdrawn it. Thank you to everyone who took the time to review
it.

Today, I would like to introduce a new, much simpler, and highly focused
RFC: `array_match()`

Currently, if we want to filter an array to find elements containing a
specific substring, we have to rely on `array_filter()` combined with a
closure and `strpos()`/`stripos()`. This pattern is not only verbose but
also carries the performance overhead of executing a PHP closure for every
single array element.

I am proposing a native function to handle this efficiently in C:
`array_match(array $array, string $needle, bool $ignore_case = false):
array`

This function preserves the original keys, safely casts values to strings,
and provides a clean, intent-revealing syntax. By implementing this
internally, we can significantly improve both readability and execution
speed compared to userland polyfills.

You can find all the use cases and examples detailed on the RFC page:
https://wiki.php.net/rfc/array_match

I look forward to hearing your thoughts and feedback on this proposal!

Best regards,
Sepehr Mahmoudi
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.