$actresses = array(
1 => "Natalie Wood",
2 => "Audrey Hepburn",
3 => "Marilyn Monroe",
4 => "Grace Kelly",
5 => "Olivia Hussey");
$actressestoday = array(
6 => "Jennifer Lopez",
7 => "Jennifer Love Hewitt",
8 => "Paula Newman",
9 => "Lindsay Lohan",
10 => "Michelle Branch",
11 => "Olivia Hussey");
如何使用函数从数组中仅提取Olivia Hussey?基本上,我如何组合两列,然后使用PHP中的函数为Olivia Hussey输出单个值?
我已尝试过以下操作,但它无效:
$allactresses = array_intersect($actresses, $actressestoday);
$value = array_column($allactresses, '11');
感谢。
答案 0 :(得分:0)
根据documentation,键来自* first“数组,而不是第二个。所以这可能有效:
$allactresses = array_intersect($actresses, $actressestoday);
$value = $allactresses[5];
答案 1 :(得分:0)
array_intersect()和reset()是要走的路:
$result = reset(array_intersect($actressestoday, $actresses));
echo $result;
//Olivia Hussey
array_intersect()
返回一个包含array1所有值的数组 在所有论点中都存在。请注意,密钥会被保留。
reset()
将数组的内部指针倒回到第一个元素和 返回第一个数组元素的值。