PHP内置的方法来获取数组值给出键列表 [英] PHP Built-in Method to Get Array Values Given a List of Keys

查看:113
本文介绍了PHP内置的方法来获取数组值给出键列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个'词典'阵列像这样的:

I have an 'dictionary' array such as this:

  $arr['a']=5;
  $arr['b']=9;
  $arr['as']=56;
  $arr['gbsdfg']=89;

和我需要的是,鉴于数组键的列表,我可以检索相应的数组值的方法。换句话说,我要寻找一个内置的功能如下方法:

And I need a method that, given a list of the array keys, I can retrieve the corresponding array values. In other words, I am looking for a built-in function for the following methods:

function GetArrayValues($arrDictionary, $arrKeys)
{
  $arrValues=array();
  foreach($arrKeys as $key=>$value)
  {
     $arrValues[]=$arrDictionary[$key]
  }
  return $arrValues;
}

我真讨厌写这种繁琐的转变,我必须找到一个内置的方法来做到这一点。任何想法?

I am so sick of writing this kind of tedious transformation that I have to find a built-in method to do this. Any ideas?

推荐答案

<一个href=\"http://www.php.net/manual/en/function.array-intersect-key.php\"><$c$c>array_intersect_key

这篇关于PHP内置的方法来获取数组值给出键列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆