Skip to content
Advertisement

Finding value from another one in an array of arrays

I got the follwing array and I would like to retrieve the name by the id:

JavaScript

It is doable with double foreach loop and a conditional test, but is there a more elegant way?

Advertisement

Answer

You can use array_column to map ids to names:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement