Re: [PHP-DEV] [RFC] array_search_range

[email protected] ("Rowan Tommins [IMSoP]")
Newsgroups php.internals
Message-ID <[email protected]>
On 12 August 2026 23:56:55 BST, Morgan <[email protected]> wrote:
>On 2026-08-13 02:27, سپهر محمودی wrote:
>> Hi everyone,
>> 
>> The main motivation is to provide a memory-efficient way to search within a specific range of an array, avoiding the overhead of creating intermediate arrays with array_slice().
>> 
>Have you thought about expanding this idea to include other functions with similar jobs (e.g. array_find, array_find_key, array_all, array_any)?


I think it would be better to design something more composable - that is, a way to create a "lazy array slice", and then accept that in functions which can use it safely. 

Swift, for instance, has both ArraySlice and Substring types which let you refer to a subset of an array or string without copying any data: <https://developer.apple.com/documentation/swift/arrayslice> <https://developer.apple.com/documentation/swift/substring>

It's conceptually similar to using an Iterator instead of filling an array with a range of values.

Regards,

Rowan Tommins
[IMSoP]
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.