Reputation: 1641
I have two arrays as shown blow
//array 1
Array
(
[0] => 223
[1] => 216
)
/array 2
Array
(
[221] => Bakers
[220] => Construction
[223] => Information Technology
[216] => Jewellery
[217] => Photography
[222] => Retailers
)
I want that text where key (values) of first array matches to second array (keys).
expected result:
Information Technology, Jewellery
Upvotes: 3
Views: 76
Reputation: 8595
$result = array();
foreach( $array1 as $index ) {
$result[] = $array2[ $index ];
}
echo implode( ', ', $result );
Upvotes: 2
Reputation: 59701
Just get the array_intersect_key()
of the keys, but since you have the keys as values in the first array you have to flip it with array_flip()
, e.g.
print_r(array_intersect_key($array2, array_flip($array1)));
Upvotes: 6