note 109706 modified in function.array-intersect-key by danbrown

From: Date: Fri, 31 Aug 2012 16:36:14 +0000
Subject: note 109706 modified in function.array-intersect-key by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-190386@lists.php.net to get a copy of this message
Simple key white-list filter:

<?php
$arr = array('a' => 123, 'b' => 213, 'c' => 321);
$allowed = array('b', 'c');

print_r(array_intersect_key($arr, array_flip($allowed)));
?>

Will return:
Array
(
 [b] => 213
 [c] => 321
) --was-- Simple key white-list filter: $arr = array('a' => 123, 'b' => 213, 'c' => 321); $allowed = array('b', 'c'); print_r(array_intersect_key($arr, array_flip($allowed))); Will return: Array ( [b] => 213 [c] => 321 ) http://php.net/manual/en/function.array-intersect-key.php

« previous php.notes (#190386) next »