【发布时间】:2012-09-23 07:28:20
【问题描述】:
可能重复:
PHP Built-in Method to Get Array Values Given a List of Keys
PHP 是否有针对此目的的内置函数?
我有两个数组,第一个与一些数据相关联。例如:
$data = array(
'name' => 'John',
'last_name' => 'Smith',
'address' => 'NY, ...',
'phone' => '1234567'
);
还有另一个带键的数组:
$keys = array(
'name',
'last_name'
);
应用此函数后,我只从第一个数组中获取值,其中的键来自第二个数组。
$result = function($data, $keys);
print_r($result);
// array(
// 'name' => 'Jonh',
// 'last_name' => 'Smith'
// )
【问题讨论】:
-
请在提出stackoverflow.com/questions/ask-advice 中要求您做的问题之前使用搜索功能。谢谢