title: Generate switch cases in php from an array?
body: <p>Is it possible to generate the cases for a switch in php using an array? Something like:</p>
  
  <pre><code>$x=array(
      0 =&gt; 'foo',
      1 =&gt; 'bar',
      2 =&gt; 'foobar'
  );
  
  $y='foobar'
  
  switch($y) {
      foreach($x as $i) {
          case $i:
              print 'Variable $y tripped switch: '.$i.'&lt;br&gt;';
              break;
      }
  }
  </code></pre>
  
  <p>I would like to be able to pull the case values from a database and loop through them with a while() loop.</p>