I have a table field that stores the price range. (Out of 5) I want to display it in this manner. If the range is 3, then display $$$ and other 2 ($) muted. What is the best approach or what is this called? (Check the below image for reference)
CodePudding user response:
You could make use of for loop as follows:
$range = 3;
for($i=0; $i<5; $i ){
if($i < $range){
echo "<strong>$</strong>";
}else{
echo "<span class='text-muted'>$</span>";
}
}
and you have to add CSS like:
.text-muted {
color: #777;
}
Update
You can also use it as a function:
<?php
function displayRangeAsDollar($range){
$boldText = '';
$mutedText = '';
for($i=0; $i<5; $i ){
if($i < $range){
$boldText .= '$';
}else{
$mutedText .= '$';
}
}
return "<strong>".$boldText."</strong>"."<span class='text-muted'>".$mutedText."</span>";
}
echo displayRangeAsDollar(3);