- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
$start = "2016-11-29";
$end = "2016-12-31";
$nnomer = "lux";
const SQL_GET_MENU_NOMERPRICE = '
SELECT `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`, `11`, `12` FROM nomerprice WHERE name = :name
';
$pdo = new PDO($dsn, $user, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $pdo->prepare(SQL_GET_MENU_NOMERPRICE);
$res = $stmt->execute([':name' => $nnomer]);
$nprice = json_encode(array_pop($stmt->fetchAll(PDO::FETCH_OBJ)), JSON_NUMERIC_CHECK);
// $nprice сейчас равен {"1":1500,"2":1000,"3":2000,"4":1000,"5":1500,"6":2000,"7":1500,"8":2000,"9":1500,"10":3000,"11":2000,"12":1500}
if (!empty($start) && !empty($end)) {
$startDate = new DateTime($start);
$endDate = new DateTime($end);
$dates = array($startDate, $endDate);
$pricesPerMonth = array(
1 => 1500, 2 => 2000, 3 => 1500, 4 => 2000, 5 => 1500,
6 => 2000, 7 => 1500, 8 => 2000, 9 => 1500, 10 => 2000,
11 => 1500, 12 => 2000
);
$price = 0;
for ($i = $startDate->getTimestamp(); $i <= $endDate->getTimestamp(); $i += 86400) {
$newDate = new DateTime();
$newDate->setTimestamp($i);
$m = $newDate->format('m');
$m = intval($m);
if ($pricesPerMonth[$m]) {
$price += $pricesPerMonth[$m];
}
}
var_dump($price);
}
AnalniyTerzatel 05.12.2016 11:43 # −1
SpearMint 05.12.2016 14:32 # 0