I feel really stupid right now since I can remember doing something like this. But now my head is empty and this really seems to look like a problem.
I have two arrays. First:
array (
0 =>
array (
'id' => '1',
'name' => 'Blizzard',
'slug' => 'blizzard',
),
1 =>
array (
'id' => '2',
'name' => 'Id Software',
'slug' => 'id-software',
),
2 =>
array (
'id' => '3',
'name' => 'Capcom',
'slug' => 'capcom',
),
3 =>
array (
'id' => '4',
'name' => 'Maxis',
'slug' => 'maxis',
),
4 =>
array (
'id' => '5',
'name' => 'Electronic Arts',
'slug' => 'electronic-arts',
),
)
And secound one:
array (
0 => '3',
1 => '4',
)
What I want to do is, take value from the secound array and match it with the value of the first one. How can I do this?
When you say “by value”, I’m assuming you meant by
idvalue, in which case, if you already know that theidvalue is one less than the key, you can do this:Otherwise, you’ll have to loop / search for the specific
id:However, another trick you can use to just get an array containing the elements you want is to use
array_filter(), like so:Now
$keepwill contain an array of the two values you want, and you can loop over them accordingly.