php - how do I get the switch command to work if the field is empty to return n/a -
hello wrote following code i'm having small problem.
in data base have field called gf_gemstone
wrote switch script (below)
the last part want write if field empty
return n/a
. no matter can't work. can body help.
case "gf_gemstone_amazon1a": switch ($value) { case "agate": return "agate"; break; case "amethyst": return "amethyst"; break; case "aquamarine": return "aquamarine"; break; case "black diamond": return "black-diamond"; break; case "black sapphire": return "sapphire"; break; case "blue diamond": return "blue-diamond"; break; case "blue sapphire": return "blue-sapphire"; break; case "blue topaz": return "blue-topaz"; break; case "chalcedony": return "chalcedony"; break; case "citrine": return "citrine"; break; case "cognac diamond": return "brown-diamond"; break; case "diamond": return "diamond"; break; case "emerald": return "emerald"; break; case "garnet": return "garnet"; break; case "green amethyst": return "green-quartz"; break; case "green quartz": return "green-quartz"; break; case "green sapphire": return "green-sapphire "; break; case "lemon quartz": return "lemon-quartz"; break; case "morganite": return "morganite"; break; case "multi sapphire": return "sapphire"; break; case "onyx": return "onyx"; break; case "opal": return "opal"; break; case "orange sapphire": return "sapphire"; break; case "peridot": return "peridot"; break; case "pink sapphire": return "pink-sapphire"; break; case "pink sapphire": return "pink-sapphire"; break; case "pink topaz": return "pink-topaz"; break; case "pink tourmaline": return "pink-tourmaline"; break; case "quartz": return "quartz"; break; case "rose quartz": return "rose-quartz"; break; case "rhodolite garnet": return "rhodolite-garnet"; break; case "ruby": return "ruby"; break; case "sapphire": return "sapphire"; break; case "smokey quartz": return "smoky-quartz"; break; case "spessartite": return "spessartite-garnet"; break; case "tanzanite": return "tanzanite"; break; case "tsavorite": return "tsavorite"; break; case "turquoise": return "turquoise"; break; case "white sapphire": return "sapphire"; break; case "yellow diamond": return "yellow-diamond"; break; case "yellow sapphire": return "sapphire"; break; case "": return "n/a"; break; default: return ""; } break;
you write far more compactly as:
$stones = array('agate' => 'agate', 'amethyst' => 'amethyst', etc...); if (in_array($value, array_keys($stones))) { return $stones[$val]; } else { return "n/a"; }
Comments
Post a Comment