Create group of number ranges between two static numbers
I want to make a simple algorithm in PHP that has as scope to generate automatically group of numbers between a range.
Let me be more clear to you. I have a price filter section for an e-shop collection page. What I do is I'm grabbing the minimum and the maximum price from the database of products, then I would like to create groups of those numbers .
Let's suppose that the minimum price of a product is 50 dollars and the maximum one is 300 dollars. What I would like to do is something like this:
Choose price range:
[checkbox here] 50 - 100
[checkbox here] 101 - 150
[checkbox here] 151 - 200
[checkbox here] 201 - 250
[checkbox here] 251 +
So at the end to grab automatically the min and max value and create automatically groups.
I started something like this, but I'm stuck:
for ( $x = $minPrice; $x < $maxPrice; $x++ ) {
if ( $x % 50 == 0 ) {
echo $x;
}
}
Thank you in advance!
以下是我能够理解您期望的代码:
$range = "";
for($i = 0; $i <= 300; $i += 50) {
$range = $i<250 ? ($i.'-'.($i+50)) : "250+";
echo '<input type="checkbox" value="'.$i.'">Range '.$range.'<br>';
}
链接地址: http://www.djcxy.com/p/58584.html
上一篇: 比较2个不同的值会返回true
下一篇: 在两个静态数字之间创建一组数字范围