title: Would an array be more effective than a switch case for this scenario?
body: <p>I'm displaying star ratings based on input from an API (note: only displaying, not receiving ratings at all). The following code works exactly as I need it to, but it's a very large piece of logic for something that feels like it could be massively simplified.</p>
  
  <p>I read a few other tickets here that suggest that using an array might be more effective than a switch case. But because the logic depends on each case between true within a range of numbers (like more than 2.5 but less than 3) I'm not sure an array would work at all in this case.</p>
  
  <p>Bottom line is this: Can this code be massively simplified somehow?</p>
  
  <pre><code>$stars = 3.5;
  
  switch ($stars) {
    case ($stars &gt; 1 &amp;&amp; $stars &lt;= 1.5):
      $star2 = 'dashicons-star-half';
      $star3 = 'dashicons-star-empty';
      $star4 = 'dashicons-star-empty';
      $star5 = 'dashicons-star-empty';
      break;
    case($stars &gt; 1.5 &amp;&amp; $stars &lt;= 2):
      $star2 = 'dashicons-star-filled';
      $star3 = 'dashicons-star-empty';
      $star4 = 'dashicons-star-empty';
      $star5 = 'dashicons-star-empty';
      break;
    case($stars &gt; 2 &amp;&amp; $stars &lt;= 2.5):
      $star2 = 'dashicons-star-filled';
      $star3 = 'dashicons-star-half';
      $star4 = 'dashicons-star-empty';
      $star5 = 'dashicons-star-empty';
      break;
    case($stars &gt; 2.5 &amp;&amp; $stars &lt;= 3):
      $star2 = 'dashicons-star-filled';
      $star3 = 'dashicons-star-filled';
      $star4 = 'dashicons-star-empty';
      $star5 = 'dashicons-star-empty';
      break;
    case($stars &gt; 3 &amp;&amp; $stars &lt;= 3.5):
      $star2 = 'dashicons-star-filled';
      $star3 = 'dashicons-star-filled';
      $star4 = 'dashicons-star-half';
      $star5 = 'dashicons-star-empty';
      break;
    case($stars &gt; 3.5 &amp;&amp; $stars &lt;= 4):
      $star2 = 'dashicons-star-filled';
      $star3 = 'dashicons-star-filled';
      $star4 = 'dashicons-star-filled';
      $star5 = 'dashicons-star-empty';
      break;
    case($stars &gt; 4 &amp;&amp; $stars &lt;= 4.5):
      $star2 = 'dashicons-star-filled';
      $star3 = 'dashicons-star-filled';
      $star4 = 'dashicons-star-filled';
      $star5 = 'dashicons-star-half';
      break;
    case($stars &gt; 4.5):
      $star2 = 'dashicons-star-filled';
      $star3 = 'dashicons-star-filled';
      $star4 = 'dashicons-star-filled';
      $star5 = 'dashicons-star-filled';
      break;
    default:
    $star2 = 'dashicons-star-empty';
    $star3 = 'dashicons-star-empty';
    $star4 = 'dashicons-star-empty';
    $star5 = 'dashicons-star-empty';
  }
  
  ?&gt;
   &lt;div class="wporg-ratings" title="&lt;?php echo $stars; ?&gt; out of 5 stars" style="color:#e6b800;"&gt;
     &lt;span class="dashicons dashicons-star-filled"&gt;&lt;/span&gt;
     &lt;span class="dashicons &lt;?php echo $star2; ?&gt;"&gt;&lt;/span&gt;
     &lt;span class="dashicons &lt;?php echo $star3; ?&gt;"&gt;&lt;/span&gt;
     &lt;span class="dashicons &lt;?php echo $star4; ?&gt;"&gt;&lt;/span&gt;
     &lt;span class="dashicons &lt;?php echo $star5; ?&gt;"&gt;&lt;/span&gt;
   &lt;/div&gt;
  </code></pre>