从数组数组中检索代码

时间:2011-01-04 09:50:35

标签: php arrays multidimensional-array

大家好 我有以下数组:

   var $status = array('pending' => array('code'=>1,'t_sys_lang'=>248),
                       'approved' =>array('code'=>2,'t_sys_lang'=>214),
                       'rejected' =>array('code'=>3,'t_sys_lang'=>252));

如果我只有代码值(1,2,...),怎么能得到t_sys_lang值(248,214 ....)?

2 个答案:

答案 0 :(得分:0)

 function getTSLByCode($code) {
   foreach ($GLOBALS['status'] as $k=>$v) {
    if ($v['code'] == $code) return $v['t_sys_lang'];
   }

   return false;
 }

 $t_sys_lang = getTSLByCode( //code );

答案 1 :(得分:-1)

$array = array(1,2,3);
foreach ($status as $v)
    if (in_array($v['code'],$array)) echo $v['t_sys_lang'];