编程语言
首页 > 编程语言> > php – 如何获得两个数组的键相交?

php – 如何获得两个数组的键相交?

作者:互联网

我有两个阵列如图所示

//array 1
Array
(
    [0] => 223
    [1] => 216
)

/array 2
Array
(
    [221] => Bakers
    [220] => Construction
    [223] => Information Technology
    [216] => Jewellery
    [217] => Photography
    [222] => Retailers
)

我想要第一个数组的键(值)与第二个数组(键)匹配的文本.

预期结果:

Information Technology, Jewellery

解决方法:

$result = array();
foreach( $array1 as $index ) {
  $result[] = $array2[ $index ];
}
echo implode( ', ', $result );

标签:php,arrays,array-intersect
来源: https://codeday.me/bug/20190724/1527300.html