TechniqueCreate associative array mapping and then get the substring of the input, like so: <?php function do_function ($option) { switch ($option) { case "Send": print "Sent"; break; case "Delete": print "Deleted"; break; case "Open Mail": print "Mail Opened"; break; case "Read Message": print "Message Read"; break; case "Reply-to Message": print "Reply-to Message"; break; } } $mappings = array ("S" => "Send", "D" => "Delete", "O" => "Open Mail", "R" => "Read Message", "T" => "Reply-to Message"); do_function ($mappings[strtoupper (substr ($input, 0, 1))]); ?> CommentsAllowing for abbreviations makes your function more forgiving of user input, and saves your user the time of having to type in exactly what he wants. This function creates an associative array in which the first letter the user enters is really all that matters. |