Skip to content
Advertisement

Making an array out of substr_replace

Hi everyone newbie here,

I’m taking on the tedious task of changing a bunch of IDs for a game and turning them into a string. As you can see here I do this for ID 29 and turn it into Sharpshooter. Is there a more efficient way for me to do this? Or am i stuck writing about 100 more if cases?

JavaScript

Below is my full code and I have added a few more examples of what I’m talking about.

JavaScript

Advertisement

Answer

Create your own translation array. If the value is not a key in the array, do not replace it.

JavaScript

Assuming you are using a loop, the translation array should be written before the loop.

Alternatively, this could all be executed in the sql with a CASE block.


Ultimately, I would advise you to avoid performing this operation on every call of your query. You should simply add these translations as a new column in PvPRanking (or where most appropriate) and add them to the result set. In other words, whatever table has the JobCode values listed as unique values — that table should receive the new column.

If you DON’T have a table that contains these unique jobcodes, then you should make one and join that table to your existing query. This is the most professional and maintainable solution because when you need to update the list, you only need to update the table instead of potentially multuple files in your project.

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