I am a novice programmer. I need to write a little code. There is a number 2833, you need to output the day in the format 12.09.2018 with this number, then the next day 13.09.2018 with the number 2858. And every next day with a number more than the previous one by 25. The code should end at 10033. I wrote a cycle

<?php for ($a = 2833; $a <=10033; $a=$a+25) { echo "Рейтинг : ". $a . "<br />"; } ?> 

There is an assumption that the date needs to be translated into a string and create a cycle that would add 86400 and translate into a date again. How sensible can this be done? All results display a column on the page

  • one
    Take the steps: 1) Start with a cycle in increments of 25 and up to 10,000. Check what works and output 2) create a date object and ply by day, checking that it works 3) combine steps 2 and 3 - gil9red
  • four
    And what, in fact, is the question? - Yuriy Prokopets
  • At 10,000 finish will not work. It’s impossible to get 10,000 by adding 25 to 2708. - Enikeyschik
  • @ Enikeyschik well, you need to do a check> = 10,000 - vladimirch

2 answers 2

 <?php $A = []; for ($a = strtotime('12 September 2018'); $a <= strtotime('27 June 2019'); $a += 86400) { $A[] = $a; } $B = []; for ($b = 2833; $b <= 10033; $b += 25) { $B[] = $b; } foreach ($A as $k => $v) { echo date('dmY', $v) .' — '. (isset($B[$k]) ? $B[$k] : '-') . PHP_EOL; // .'<br />'; } 
  • one
    What a fun way to format code. Do you understand this at all? - teran

To work on a date there is a great function strtotime , which can work with relative dates through constructions of the form +10 days . We add to the cycle one more counter by days (we will increase "manually" in the cycle). And let's take this second counter to increase the days:

 $startDate = strtotime("12.09.2018"); $days = 0; for ($a = 2833; $a <= 10033; $a = $a + 25) { echo "Рейтинг : ". $a . " за дату " . date("Ymd", strtotime("+{$days} days", $startDate)) . "<br />"; $days++; }