Star rating with half star support



PHP Snippet 1:

<?php
$totalRating = 5;
$starRating = 2.5;

for ($i = 1; $i <= $totalRating; $i++) {
     if($starRating < $i ) {
        if(is_float($starRating) && (round($starRating) == $i)){
            echo "<img src=\"/icons/star-half.svg\">";
        }else{
            echo "<img src=\"/icons/star-empty.svg\">";
        }
     }else {
        echo "<img src=\"/icons/star.svg\">";
     }
}
?>

PHP Snippet 2:

<?php
     for ($i = 1; $i <= $totalRating; $i++) {
     if ($starRating < $i ) {
        echo "<img src=\"/icons/star-empty.svg\">";
     } elseif(is_int($starRating) === false) {
        echo "<img src=\"/icons/star_half.svg\">";
     } else {
        echo "<img src=\"/icons/star.svg\">";
      }
    }
?>

PHP Snippet 3:

<?php
     for ($i = 1; $i <= $totalRating; $i++) {
     if ($starRating < $i ) {
        echo "<img src=\"/icons/star-empty.svg\">";
     } elseif(is_int($starRating) === false) {
        echo "<img src=\"/icons/star-" . floatval($starRating)) . ".svg\">";
     } else {
        echo "<img src=\"/icons/star.svg\">";
      }
    }
?>