Skip to content
Advertisement

Replace column values in result set using a lookup/dictionary array

You can find the entire code below.

I have 2 arrays. The first array looks like this:

JavaScript

The second array is this: (from a mysqli result set)

JavaScript

I want to replace the logMessage values in the second array with the corresponding $replacements value.

How it should look:

JavaScript

Must be

JavaScript

Current code:

JavaScript

Advertisement

Answer

Maybe something like the following. Grabs the key values of $replacements and if the value of a key in $array is found, it will replace the the value with the $replacement value.

JavaScript

EDIT

So let me apply the same logic to the rest of your array. Suppose we have the following array (I pulled this from your question above):

JavaScript

Now I can iterate over this array with the following:

JavaScript

This will output the following:

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