note 125388 added to function.array-filter
| From: | (mail@chayan.me) | Date: | Tue, 22 Sep 2020 17:43:33 +0000 |
| Subject: | note 125388 added to function.array-filter | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-215457@lists.php.net to get a copy of this message | ||
/**
* Remove key from multidimensional array
*
* @param array $request
* @param array $keys
*
* @return array
*/
function request_filter(array $request, array $keys) {
array_walk($request, function (&$value, $key) use ($keys) {
if(is_array($value)) {
$value = request_filter($value, $keys);
}
});
return array_filter ($request, function ($value, $key) use ($keys) {
return ! in_array($key, $keys);
}, ARRAY_FILTER_USE_BOTH);
}
$data = [
'a' => 'A',
'password' => 123,
'data' => [
'b' => 'B',
'data2' => [
'c' => 'C',
'password' => 545,
],
'password' => 321,
]
];
print_r(request_filter($data, ['password']));
Output will be:
Array
(
[a] => A
[data] => Array
(
[b] => B
[data2] => Array
(
[c] => C
)
)
)
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.172 (proxied: 134.209.110.31)
----
Manual Page -- http://php.net/manual/en/function.array-filter.php
Edit -- https://master.php.net/note/edit/125388
Del: integrated -- https://master.php.net/note/delete/125388/integrated
Del: useless -- https://master.php.net/note/delete/125388/useless
Del: bad code -- https://master.php.net/note/delete/125388/bad+code
Del: spam -- https://master.php.net/note/delete/125388/spam
Del: non-english -- https://master.php.net/note/delete/125388/non-english
Del: in docs -- https://master.php.net/note/delete/125388/in+docs
Del: other reasons-- https://master.php.net/note/delete/125388
Reject -- https://master.php.net/note/reject/125388
Search -- https://master.php.net/manage/user-notes.php