note 118192 added to function.array-fill-keys
| From: | ntd at entidi dot it | Date: | Fri, 23 Oct 2015 19:04:18 +0000 |
| Subject: | note 118192 added to function.array-fill-keys | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204010@lists.php.net to get a copy of this message | ||
To remove arbitrary keys from an associative array:
<?php
function nuke_keys($keys, $array) {
return array_diff_key($array, array_fill_keys($keys, 0));
}
$array = array('blue' => 1, 'red' => 2, 'green' => 3,
'purple' => 4);
$keys = array('red', 'purple');
print_r(nuke_keys($keys, $array));
?>
The above snippet will return:
Array
(
[blue] => 1
[green] => 3
)
----
Server IP: 72.52.91.14
Probable Submitter: 88.149.182.35
----
Manual Page -- http://php.net/manual/en/function.array-fill-keys.php
Edit -- https://master.php.net/note/edit/118192
Del: integrated -- https://master.php.net/note/delete/118192/integrated
Del: useless -- https://master.php.net/note/delete/118192/useless
Del: bad code -- https://master.php.net/note/delete/118192/bad+code
Del: spam -- https://master.php.net/note/delete/118192/spam
Del: non-english -- https://master.php.net/note/delete/118192/non-english
Del: in docs -- https://master.php.net/note/delete/118192/in+docs
Del: other reasons-- https://master.php.net/note/delete/118192
Reject -- https://master.php.net/note/reject/118192
Search -- https://master.php.net/manage/user-notes.php