3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $facturation = [ 'start_time' => '27/06/2017', 'mtt' => '50000', 'periodicite' => '12' ]; var_dump(date('Y-m-d H:i:s', strtotime(str_replace('/', '-', $facturation['start_time'])))); die; // generate tasks depending on amount (/x days + rest in last // start_time and end_time accordingly $tasks_data = []; $current_start_time = date('Y-m-d', strtotime(str_replace('/', '-', $facturation['start_time']))); // calculate mtt per month approximately $mtt_per_period = floatval($facturation['mtt']) / floatval($facturation['periodicite']); $mtt_per_period = number_format((float)$mtt_per_period, 2, '.', ''); $delta_time = ($facturation['periodicite'] == '12') ? '1 month' : '1 year'; for ($i=0; $i < $facturation['periodicite'] ; $i++) { $current_end_time = date('d/m/Y', strtotime($current_start_time . ' +' . $delta_time)); $budget = $mtt_per_period; if ($i === intval($facturation['periodicite'])-1) { $budget = floatval($facturation['mtt']) - ((floatval($facturation['periodicite'])-1) * $mtt_per_period); $budget = number_format((float)$budget, 2, '.', ''); } $tasks_data[] = [ 'start_time' => $current_start_time, 'end_time' => $current_end_time, 'title' => ($facturation['periodicite'] == '12') ? 'acompte ' . '' . explode('/', $current_start_time)[2] : 'échéance unique', 'budget' => $budget ]; $current_start_time = date('d/m/Y', strtotime($current_start_time . ' +' . $delta_time)); } var_dump($tasks_data);
based on gYpGN
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.2.6
string(19) "2017-06-27 00:00:00"