php code

aswathi rajasekar
aswathi rajasekar used Ask the Experts™
on
while using php code for each month and date .....why cant we use "if condition" or any other looping condition
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
I don't understand your question. It might help to see an example of what you have and what you want. In the meantime, here's an example of looping through the next 12 months:

<?php
$date = new DateTime();
for($i = 0; $i < 12; $i++)
{
  echo $date->format('Y-m') . "\n";
  $date->modify('+1 month');
}

Author

Commented:
yea this is what is asked..thnq
Most Valuable Expert 2011
Top Expert 2016

Commented:
Some background information might be helpful.

Old, procedural examples (for historical purposes only):
https://www.experts-exchange.com/articles/11271/Understanding-Client-Server-Protocols-and-Web-Applications.html

Modern object-oriented examples (what you should be learning and using today):
https://www.experts-exchange.com/articles/20920/Handling-Time-and-Date-in-PHP-and-MySQL-OOP-Version.html

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial