note 127052 added to function.array-filter
| From: | TechNyquist at main dot php dot net | Date: | Fri, 13 May 2022 18:36:17 +0000 |
| Subject: | note 127052 added to function.array-filter | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-218377@lists.php.net to get a copy of this message | ||
Keep in mind that, as of PHP 7.4 and above, you can use arrow functions to as argument.
So for example if you want to leave values bigger than 10:
<?php
$arr = array_filter($numbers, fn($n) => $n > 10);
?>
also, combine with key-flag to cut certain keys:
<?php
$arr = array_filter($entries, fn($key) => !in_array($key, ['key1',
'key5']), ARRAY_FILTER_USE_KEY);
?>
and so on.
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.47 (proxied: 79.35.67.65)
----
Manual Page -- https://php.net/manual/en/function.array-filter.php
Edit -- https://main.php.net/note/edit/127052
Del: integrated -- https://main.php.net/note/delete/127052/integrated
Del: useless -- https://main.php.net/note/delete/127052/useless
Del: bad code -- https://main.php.net/note/delete/127052/bad+code
Del: spam -- https://main.php.net/note/delete/127052/spam
Del: non-english -- https://main.php.net/note/delete/127052/non-english
Del: in docs -- https://main.php.net/note/delete/127052/in+docs
Del: other reasons-- https://main.php.net/note/delete/127052
Reject -- https://main.php.net/note/reject/127052
Search -- https://main.php.net/manage/user-notes.php