note 89126 added to function.array-intersect-key
| From: | pdemaziereatgmaildotcom at osu1 dot php dot net | Date: | Mon, 23 Feb 2009 15:52:26 +0000 |
| Subject: | note 89126 added to function.array-intersect-key | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-151016@lists.php.net to get a copy of this message | ||
Just a simple script if you want to use one array, which contains only zeros and ones, as mask for
another one (both arrays must have the same size of course). $outcome is an array that contains only
those values from $source where $mask is equal to 1.
$outcome = array_values(array_intersect_key( array_values($source),
array_filter(array_values($mask)) ));
PS: the array_values() function is necessary to ensure that both arrays have the same
numbering/keys, otherwise your masking does not behave as you expect.
Enjoy!
----
Server IP: 195.207.10.20
Probable Submitter: 134.58.34.54
----
Manual Page -- http://www.php.net/manual/en/function.array-intersect-key.php
Edit -- https://master.php.net/note/edit/89126
Del: integrated -- https://master.php.net/note/delete/89126/integrated
Del: useless -- https://master.php.net/note/delete/89126/useless
Del: bad code -- https://master.php.net/note/delete/89126/bad+code
Del: spam -- https://master.php.net/note/delete/89126/spam
Del: non-english -- https://master.php.net/note/delete/89126/non-english
Del: in docs -- https://master.php.net/note/delete/89126/in+docs
Del: other reasons-- https://master.php.net/note/delete/89126
Reject -- https://master.php.net/note/reject/89126
Search -- https://master.php.net/manage/user-notes.php