Spaced Price Listing with PHP

I would like to list the periodic price with php. How can I do it?

For example: 100€ to 500€

Result:
100€ - 200€
200€ - 300€
300€ - 400€
400€ - 500€

This is my current code:

$start = 100; 
$end = 500;
$step = 50; 
foreach(range($start, $end, $step) as $i) {
    if ($start < $i) { 
        echo ' - '.$i.'<br>'; 
    }
    switch ($i) { 
        default : echo $i; 
    }
    if($end <= $i) {
         echo ' - Üstü';
    }
} 

This outputs:

100 - 150 
150 - 200 
200 - 250 
250 - 300 
300 - 350 
350 - 400 
400 - 450 
450 - 500 
500

How can I get rid of the last price?

Upvotes: 0

Views: 40

Answers (1)

Aggie
Aggie

Reputation: 139

A simple for loop should be enough

$min = 100;
$max = 500;
$step = 50;

for($i = $min;  $i < $max; $i += $step){

    echo $i.'€ - '.($i+$step).'€ <br>';

}

Upvotes: 1

Related Questions