Skip to content

Instantly share code, notes, and snippets.

@RimonEkjon
Forked from JeffreyWay/gist:1268154
Created August 26, 2014 09:01
Show Gist options
  • Save RimonEkjon/a8caf6984dca0768afb1 to your computer and use it in GitHub Desktop.
Save RimonEkjon/a8caf6984dca0768afb1 to your computer and use it in GitHub Desktop.
<?php
# Instead of
$name = 'Jeff';
switch ($name) {
case 'Jeff':
echo "I'm Jeff";
break;
case 'Joe':
echo "I'm Joe";
break;
case 'John':
echo "I'm John";
break;
}
# Do
$lookup = array(
"Jeff" => "I'm Jeff",
"Joe" => "I'm Joe",
"John" => "I'm John",
"default" => "I'm Error"
);
echo $lookup[$name];
# Or if you need a default
echo isset($lookup[$name]) ? $lookup[$name] : $lookup['default'];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment