title: Dynamically generate cases for switch statement using an array
body: <p>I'm creating a script to auto generate an RSS feed for the various sections of my website. I've queried by database and have an array of data which represents each section called <code>$showData</code>. I'm using a <code>switch</code> statement to setup various variables depending upon the section of the site. Instead of having to change this script each time I add a show, I'd like the <code>case</code> in my <code>switch</code> statement to be dynamic.</p>
  
  <pre><code>&lt;?php
  switch($section){
      case 'show1':
          $title = $showData['show1'] . ' Title';
          $description = $showData['show1'] . ' Description';
          break;
      case 'show2':
          $title = $showData['show2'] . ' Title';
          $description = $showData['show2'] . ' Description';
          break;
  }
  ?&gt;
  </code></pre>
  
  <p>I attempted to use a <code>foreach</code> loop to create each case, but you can't put that inside a <code>switch</code> statement. Someone else in another post I read suggested using <code>eval()</code>.</p>
  
  <p>Here's my code that I tried, that doesn't work.</p>
  
  <pre><code>&lt;?php
  switch($showFilter)}
      foreach($showFilters as $key =&gt; $value){
          case $key:
          $title = $value;
          $description = $value;
          break;
      }
  }
  ?&gt;
  </code></pre>
  
  <p>Here's a <code>print_r</code> of the array</p>
  
  <pre><code>Array
  (
      [show1] =&gt; The Name of Show One
      [show2] =&gt; The Name of Show Two
  )
  </code></pre>