If you want to find a value in only part of an array today, you cut that part out with array_slice() and then search it with array_search(). That's two calls, and the slice is a copy. This RFC from Sepehr Mahmoudi proposed array_search_range(), which searches the range you choose directly in the original array.

How it works

function array_search_range(
    mixed $needle,
    array $haystack,
    int $offset = 0,
    ?int $length = null,
    bool $strict = false,
): int|string|false

Before and after:

$haystack = ['PHP', 'Python', 'Ruby', 'PHP'];

// Before
$range = array_slice($haystack, 1, 3, true);
$key = array_search('PHP', $range, true);

// After
$key = array_search_range('PHP', $haystack, 1, 3, true);
// int(3)

Like array_search(), it returns the original key of the first match, or false if there isn't one. The range is counted by position, not by key:

$haystack = [100 => 'a', 500 => 'b', 700 => 'c'];

array_search_range('b', $haystack, 1, 1);
// int(500)

The offset and length rules:

  • A negative $offset counts from the end.
  • An $offset past the end returns false.
  • A null $length searches through to the end.
  • A $length longer than what's left stops at the end.
  • A $length of 0 returns false.
  • A negative $length leaves out that many elements at the end.
  • $strict switches the comparison between === and ==.

The RFC lists use cases like paging through large result sets, searching part of a big log file and scanning a queue. It says memory use stays flat because nothing is copied. The page also includes a userland polyfill built on array_slice().

What it means for existing code

The page has no backward compatibility section. It adds one new function, so code that already defines a global array_search_range() would clash, which is why the polyfill checks function_exists() first.

Where it stands

Sepehr Mahmoudi withdrew the RFC on August 20, 2026, without a vote. The discussion leaned toward a bigger idea, a lazy array slice that could work with more functions than just search, and Mahmoudi said the plan is to come back with a better proposal. The wiki page still says Draft.