Skip to content
Advertisement

Substitute column value in each row of a 2d array based on other rows in the same array

I have an array like so:

JavaScript

Each row has a unique record and email and the sponsor key is related to the record. So, instead of an integer, I am trying to replace the value of the sponsor key with the corresponding email based on the record, something like this:

JavaScript

I have tried using a foreach loop but it doesn’t give me the expected result:

JavaScript

Advertisement

Answer

As record is unique, I recommend rebuilding $arr using this value as the key. Then you loop again to replace your value for $sponsor

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