是否有返回数组的指定密钥的功能? [英] Is there a function to return specified keys of an array?

查看:82
本文介绍了是否有返回数组的指定密钥的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道是否有一个本地的PHP函数来执行以下操作:

I'm wondering if there is a native PHP function to do the following:

取两个参数:一个输入阵列,和键名的第二数值阵列,并且从输入阵列,其名称为第二,数字阵列中仅返回键

Take two parameters: an input array, and a second numerical array of keys names, and return only the keys from the input array whose name are in the second, numeric array.

推荐答案

您可以使用 array_intersect_key array_flip

You can use array_intersect_key and array_flip:

array_intersect_key($arr, array_flip($keys))

这篇关于是否有返回数组的指定密钥的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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