gpt4 book ai didi

php - 将数字转换为视觉评级(星星)?

转载 作者:行者123 更新时间:2023-12-03 02:02:11 25 4
gpt4 key购买 nike

在我的数据库中有数字1 , 2 , 2.5 , 3 , 3.5 , 4 , 4.55

我想将这些数字转换为星号。

我有一颗全星和半颗星。

从数据库获取信息后我该如何做到这一点?

我在数据库中有评级标签。

最佳答案

<?php
for($x=1;$x<=$starNumber;$x++) {
echo '<img src="path/to/star.png" />';
}
if (strpos($starNumber,'.')) {
echo '<img src="path/to/half/star.png" />';
$x++;
}
while ($x<=5) {
echo '<img src="path/to/blank/star.png" />';
$x++;
}
?>

*假设您使用的是 PHP

关于php - 将数字转换为视觉评级(星星)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10250825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com