I have an array:
$array = array(
'key1' => 'value1',
'key2' => 'value2',
'key3' => 'value3',
'key4' => 'value4',
'key5' => 'value5',
);
and I would like to get a part of it with specified keys – for example key2, key4, key5.
Expected result:
$result = array(
'key2' => 'value2',
'key4' => 'value4',
'key5' => 'value5',
);
What is the fastest way to do it ?
You need
array_intersect_keyfunction:Also
array_flipcan help if your keys are in array as values: