3 ms·
Too much code. Too many "if" statements that have to be executed every time. Try: <?php function getRatingImage($rating) { $vals = ['zero','half','on
by edw519 19y ago
Too much code. Too many "if" statements that have to be executed every time.
Try:
<?php
function getRatingImage($rating)
{
$vals = ['zero','half','one','one_half','two','two_half','three','three_half','four','four_half','five'];
$ndx = intval($rating * 2);
if($ndx > 10){$ndx = 10};
return "./" + $vals[$ndx] + ".jpg";
}
?>
- sanswork 19y agoI totally agree that the use of all those ifs is bad. That said a switch statement will be faster than the code you posted(Though you were thinking in another language when your wrote your snippit methinks) if speed is your concern.