Posted 15 May 2013 - 08:11 AM
Hi, I am having trouble understanding the PHP Switch function. Can someone please give an example of them and a purpose. Google isnt helping me for this so please no lmgtfy crap.
switch ($randomvariable) {
case "hello":
echo "Random variable says hello.";
break;
case "goodbye":
echo "Random variable says goodbye.";
break;
case "whatever":
echo "Random variable says whatever.";
break;
}
That's the same as doing the following in Lua:
if randomvariable == "hello" then
print("Random variable says hello.")
elseif randomvariable == "goodbye" then
print("Random variable says goodbye.")
elseif randomvariable == "whatever" then
print("Random variable says whatever.")
end