<?php
function price_item($start=0,$end=4650){
$price=0;
if($start>0 && $end<=1499){
$price += ($end-$star)*2;
}
if($start>=1500 && $end<=1700){
$price += ($end-$star)*3;
}
return $price;
}
?>
var divideSteps = [
{
step: 1500,
price: 2,
},
{
step: 200,
price: 3,
},
{
step: 500,
price: 4,
}
];
var lastStepIndex = divideSteps.length - 1;
var totalItems = 4000;
var fullPrice = 0;
divideSteps.forEach((x,i) => {
if (i === lastStepIndex) {
fullPrice += totalItems * x.price;
} else if (x.step > totalItems) {
fullPrice += x.step * x.price;
totalItems -= x.step;
} else {
fullPrice += totalItems * x.price;
totalItems = 0;
};
});