dimanche 28 janvier 2018

Best way to check if lots of variables contain a string and if so change it? PHP

I have lots of variables that I need to check to see if it is equal to "None". If a variable is equal to "None" I would like to change it to = "-";

What's the best practice way of doing this without having a separate IF function for each variable?

//Variables
$profileEthnicity = h($result["profile_ethnicity"]);
$profileHeight = h($result["profile_height"]);
$profileBuild = h($result["profile_build"]);
$profileEyeColor = h($result["profile_eye_color"]);
$profileHairColor = h($result["profile_hair_color"]);
$profileTattoos = h($result["profile_tattoos"]);
$profilePiercings = h($result["profile_piercings"]);

//Example
if($profileEthnicity == "None") { $profileEthnicity = "-"; }

Aucun commentaire:

Enregistrer un commentaire