[php-src] Issue #13996: Add new method: array_find
| From: | nicoalonso | Date: | Thu, 18 Apr 2024 15:04:09 +0000 |
| Subject: | [php-src] Issue #13996: Add new method: array_find | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-246785@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/13996
Author: nicoalonso
### Description
# Description
Add a new method called: "**array_find**"
This method could have the following signature:
```php
function array_find(array $haystack, callable $callback): mixed {}
```
This method should have the same behavior as javascript's 'Array.prototype.find'
method ([mdn
doc](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find))
Example:
```php
$data = ['dummy' => 'test',];
$keys = ['key1', 'dummy', 'key2'];
$result = array_find($keys, fn($key) => array_key_exists($key, $data));
echo $result;
// echo: dummy
```
# PHP Version
N/A
# Operating System
N/A
Thanks