<?php
//cari lama sewa
$awal = new DateTime('2012-02-01');
$akhir = new DateTime('2012-02-08');
$interval = $awal->diff($akhir);
$lamaSewa = $interval->format('%a') + 1;
$tarif = 2500;
$jumlahBarang = 10;
//masa 1
$lamaMasa1 = min(3,$lamaSewa);
echo 'Masa 1 = '.$jumlahBarang.' x 1 x '.$tarif;
$lamaSewa = $lamaSewa - $lamaMasa1;
//masa 2
if($lamaSewa > 0){
$lamaMasa2 = min(2,$lamaSewa);
echo '<br/>Masa 2 = '.$jumlahBarang.' x '.$lamaMasa2.' x '.(2*$tarif);
$lamaSewa = $lamaSewa - $lamaMasa2;
}
//masa 3
if($lamaSewa > 0){
echo '<br/>Masa 3 = '.$jumlahBarang.' x '.$lamaSewa.' x '.(3*$tarif);
}
?>