note 97208 deleted from function.array-intersect-key by danbrown

From: Date: Thu, 08 Apr 2010 13:26:45 +0000
Subject: note 97208 deleted from function.array-intersect-key by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-168015@lists.php.net to get a copy of this message
Note Submitter: iknowsomethingcom at gmail dot com ---- 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 )

« previous php.notes (#168015) next »