<?php
function getPriceForDate($date, array $pricelist){ $date = strtotime($date); foreach ($pricelist as $season) { $season_start = strtotime($season['from']); $season_end = strtotime($season['to']); if ($date > $season_start && $date < $season_end) { return $season['price']; } } // Falls kein Preis für diesen Zeitraum eingetragen => Default-Preis return 10;}function getPriceForDateRange($start, $end, array $pricelist){ $start = DateTime::createFromFormat('d.m.Y', $start); $end = DateTime::createFromFormat('d.m.Y', $end); $total = 0; while ($start < $end) { $start->modify("+1 day"); $total += getPriceForDate($start->format('Y-m-d'), $pricelist); } return $total;}$prices = [ [ 'from' => '01.01.2014', 'to' => '31.05.2014', 'price' => 10 ], [ 'from' => '01.06.2014', 'to' => '31.08.2014', 'price' => 20 ], [ 'from' => '01.09.2014', 'to' => '31.12.2014', 'price' => 15 ],];// ganzer Mai und Juni, also 1 Monat Saison 1 und 1 Monat Saison 2$user_start = "01.05.2014";$user_end = "30.06.2014";echo getPriceForDateRange($user_start, $user_end, $prices);
- Output for 5.4.0 - 5.4.31
- Parse error: syntax error, unexpected '$pricelist' (T_VARIABLE) in /in/Z4j3u on line 2
Process exited with code 255. - Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.28
- Parse error: syntax error, unexpected T_VARIABLE in /in/Z4j3u on line 2
Process exited with code 255. - Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
- Parse error: parse error, unexpected T_VARIABLE in /in/Z4j3u on line 2
Process exited with code 255. - Output for 4.3.2 - 4.3.4
- Parse error: parse error in /in/Z4j3u on line 2
Process exited with code 255.
preferences:
218.09 ms | 1395 KiB | 121 Q