S
S
Sasha Brahms2015-11-20 16:32:11
PHP
Sasha Brahms, 2015-11-20 16:32:11

Get data from the array by the keys of another?

there is an array:

$arr = array('one' => 1, 'two' => 2, 'three' => 3);

and an array:
$other = array('two','three');
How to get elements with the same keys from 2 arrays? (I don't know how to put it differently)
get 'two', 'three' ?
without additional iterations of arrays?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sunrails, 2015-11-20
@Dlike

$arr = array('one' => 1, 'two' => 2, 'three' => 3);
$other = array('two', 'three');
var_dump(array_intersect_key($arr, array_flip($other)));

W
whitysolo, 2015-11-20
@whitysolo

array_column use if 5.5 and above php version
php.net/manual/en/function.array-column.php

I
inDeepCode, 2015-11-20
@inDeepCode

array_intersect()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question