# [PATCH] New parameter for in_array() & array_search()

- Thread: https://externals.io/message/31583
- Original archive: https://news-web.php.net/php.internals/31583
- Started by Hannes Magnusson on 2007-08-15T14:59:52+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #31583 — Hannes Magnusson — 2007-08-15T14:59:52+00:00

URL: https://externals.io/message/31583#31583

Hi all

Attached* is a patch introducing a new parameter to `in_array()` and
 `array_search()` which will set the internal pointer to the first
location of $needle in the $haystack (granted that $needle exists
within the $haystack).

This will make it possible to search for a value in an array and then
run `prev()`/next() on the array to get the next/previous sibling.

I'd like to commit this after 5.2.4 has been released if there are no
objections?

-Hannes

* In case it doesn't come through: http://home.nith.no/~maghan/keeppos/

---

## #31624 — Hannes Magnusson — 2007-08-16T12:22:16+00:00

URL: https://externals.io/message/31583#31624 · In reply to: #31583

> Hi all
>
> Attached* is a patch introducing a new parameter to `in_array()` and
> `array_search()` which will set the internal pointer to the first
> location of $needle in the $haystack (granted that $needle exists
> within the $haystack).

Or should we maybe create two new functions?
bool array_seek_value(&$array, mixed $value [, bool $strict=false]);
bool array_seek_key(&$array, integer/string $key);

-Hannes

---

## #31721 — dz@bitxtender.com — 2007-08-18T22:48:58+00:00

URL: https://externals.io/message/31583#31721 · In reply to: #31583

Smells like feature creep.

Plus, it's difficult to document. I think it would be the first  
function that mutates an argument depending on another argument - it  
would also mean that the input array is passed as a reference in case  
that new flag is set.

Either way, not a good idea IMO. Especially in case of `in_array()`.

David



Am 15.08.2007 um 16:59 schrieb Hannes Magnusson:

> Hi all
>
> Attached* is a patch introducing a new parameter to `in_array()` and
> `array_search()` which will set the internal pointer to the first
> location of $needle in the $haystack (granted that $needle exists
> within the $haystack).
>
> This will make it possible to search for a value in an array and then
> run `prev()`/next() on the array to get the next/previous sibling.
>
> I'd like to commit this after 5.2.4 has been released if there are no
> objections?
>
> -Hannes
>
> * In case it doesn't come through: http://home.nith.no/~maghan/ 
> keeppos/<keeppos.patch
