Best way to determine image

Hey all,

I’m a very hands-on learner so my PHP experience is a bit all over the place but I have been trying to expand on that and I’m at a point where I can generally figure anything out I need but never know if it’s how I should actually be doing it.

Currently I need to determine a CSS class that is displayed based on what a string of text is. Each string is a country name and will correspond to a class name. There’s about 250 total.

I have figured out how to do this without issue a number of ways such as by adding another column to the database for storing the class or a big switch statement in a function but nothing I’ve done even if working feels like it’s the best/proper way to go about it.

Any direction anyone can give towards the proper way to be going about this would be appreciated.


What exactly would a switch work off of? How do you determine what country to use?

If you’re storing user data in a table and want to make this part of their user settings, adding another column sounds like a fine solution.

Thanks for the response.

In that particular example it was me storing the exact country name such as “Australia” or “United Kingdom” in my database and using it as that for a related purpose but then also using in a switch to determine the class that would get used like something($country) which would go through a switch and return the class name.

I should have clarified this data is in a table that is displayed using a foreach and each 1 will have it’s own class needing to be determined as well as having the actual country name for use.


then i’d make it so the classname is functionally derivable from the proper name.


“The class name is the exact country name, with spaces removed and all lowercase.”

(strtolower(str_replace(" “,”",$countryname)))


I think that’ll be a perfect solution for my needs, much simpler than my previous ways, that’s for sure.

Thank you very much for your input on this, much appreciated. :smile:


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.