巧用PHP数组函数

2014年3月5日 08:48:39

情景:项目中需要根据传递来的参数的不同,使用不同的缓存

假如传递来的参数最多有这几个(在这个范围内,但是每次传过来的参数不确定):

$arg = array(
    'a' => '1111',
    'b' => '2222',
    'c' => '3333',
    'd' => '4444',
    'e' => '5555'
    );

一种情况,当实参中有a或者b,或者没有参数时,将得到的结果缓存起来

 1 $arrBlackList = array(
 2     'c' => 0,
 3     'd' => 0,
 4     'e' => 0
 5     );
 6 
 7 $arrInter = array_intersect_key($arrBlackList, $arg);
 8 
 9 $intLen = count($arrInter);
10 if (!$intLen) {
11     return 1;
12 }

 

 

posted @ 2014-03-05 10:05  myD  阅读(216)  评论(0编辑  收藏  举报