note 97208 added to function.array-intersect-key
| From: | iknowsomethingcom at gmail dot com | Date: | Thu, 08 Apr 2010 12:39:01 +0000 |
| Subject: | note 97208 added to function.array-intersect-key | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-168010@lists.php.net to get a copy of this message | ||
How to apply many views to the same array?
<?php
// Let's have some list of Items
$itemsList = array (
1 => 'Item A',
2 => 'Item B',
3 => 'Item C',
4 => 'Item D'
);
// You can define as many views as you want here,
// setting keys of itemList array in particular view
$itemsView = array (
'view1' => array(1, 2, 3),
'view2' => array(1, 4),
'view3' => array(4, 2)
);
// Later in the code...
$view = 'view3';
if ($view && is_array($itemsView[$view])) {
print_r(array_intersect_key($itemsList, array_flip($itemsView[$view])));
}
else print_r($itemsList);
?>
Output view1:
Array ( [1] => Item A [2] => Item B [3] => Item C )
Output view 3:
Array ( [2] => Item B [4] => Item D )
----
Server IP: 194.24.174.37
Probable Submitter: 217.30.129.157
----
Manual Page -- http://www.php.net/manual/en/function.array-intersect-key.php
Edit -- https://master.php.net/note/edit/97208
Del: integrated -- https://master.php.net/note/delete/97208/integrated
Del: useless -- https://master.php.net/note/delete/97208/useless
Del: bad code -- https://master.php.net/note/delete/97208/bad+code
Del: spam -- https://master.php.net/note/delete/97208/spam
Del: non-english -- https://master.php.net/note/delete/97208/non-english
Del: in docs -- https://master.php.net/note/delete/97208/in+docs
Del: other reasons-- https://master.php.net/note/delete/97208
Reject -- https://master.php.net/note/reject/97208
Search -- https://master.php.net/manage/user-notes.php