Multiway if

Summary

Make a chain of ifs and elseifs for a variable that can have several different values.

Situation

A variable can take on different values in different conditions.

Action
  • $variable = initial value;
  • if (test) {
  •   $variable = something;
  • }
  • elseif (another test) {
  •   $variable = something else;
  • }
  • ...
  • else {
  •   $variable = something else again;
  • }
  • Do something with $variable;
Where referenced