[RFC] array_search_range — Concrete Use Cases

php.internals

سپهر محمودی

14 days ago
Hi everyone, After the feedback from Larry and mickmackusa, I thought it would be more helpful to lay out the concrete, real-world use cases for this function in one place, rather than discussing it in abstract terms. ------------------------------ The Core Problem array_slice() always creates a new array. For large arrays, this means significant memory overhead and slowdown, just to find the position of an element or a range of elements. array_search_range() is designed to return only the indices, without making any copy. ------------------------------ Real-World Use Cases *1. Pagination on large arrays* When you have an array with a hundred thousand elements and you only want to process a specific range, you currently have to copy the whole slice or loop over everything. This function gives you just the indices of that range. *2. Processing large log files* You read a big log file into an array and you want to find only the lines within a specific time range. Instead of a full scan or a copy, you get just the relevant positions. *3. Queues* When you want to find items between two positions without modifying or copying the queue. The function returns only the indices, leaving the queue untouched. *4. Database cache* When you cache a query result in an array and want to find a specific range of results without re-running the query. Instead of copying records, you just get the indices. ------------------------------ Why This Small Function Is Worth It - ✅ *Memory:* no copy means memory usage stays constant - ✅ *Speed:* a bounded search instead of a full scan - ✅ *Simplicity:* a small function, with no dependency on a large lazy slice project - ✅ *Available now:* usable today, not after a multi-month RFC ------------------------------ Thanks for your time. I’d love to hear your thoughts, especially if any other use cases come to mind that could be added to the RFC. Best regards, Sepehr

Larry Garfield

14 days ago
On Tue, Aug 18, 2026, at 6:59 AM, سپهر محمودی wrote:
> Hi everyone, > > After the feedback from Larry and mickmackusa, I thought it would be > more helpful to lay out the concrete, real-world use cases for this > function in one place, rather than discussing it in abstract terms.
Please keep all discussion to the original thread so it's easier to find later. Or, really, these sorts of examples belong in the RFC itself. --Larry Garfield

سپهر محمودی

14 days ago
On سه‌شنبه ۱۸ اوت ۲۰۲۶، ۱۸:۱۷ Larry Garfield <larry@garfieldtech.com> wrote:
> On Tue, Aug 18, 2026, at 6:59 AM, سپهر محمودی wrote: > > Hi everyone, > > > > After the feedback from Larry and mickmackusa, I thought it would be > > more helpful to lay out the concrete, real-world use cases for this > > function in one place, rather than discussing it in abstract terms. > > Please keep all discussion to the original thread so it's easier to find > later. Or, really, these sorts of examples belong in the RFC itself. > > --Larry Garfield >
‐----‐--------------- Hi Larry, Fair point — my apologies for splitting the thread. I’ll keep everything in the original thread from here on. You’re right that these examples belong in the RFC itself. I’ll add them to the wiki page now. Thanks for the pointer. Best regards, Sepehr