PHP每周三选择一次

I need help Select every other Wednesday starting on 5/2/12. This code below selects every other Wednesday starting on the week it currently is. But i need to set the beginning week. I am familiar with PHP, but not familiar with php dates. So please be as specific as possible. I found this:

$number_of_dates = 10;

for ($i = 0; $i < $number_of_dates; $i++) {
   echo date('m-d-Y', strtotime('Wednesday +' . ($i * 2) . ' weeks')). "<br>".PHP_EOL;
}

Use mktime to create your starting date and pass that as the second argument to strtotime so that counting starts from there:

$startDate = mktime(0, 0, 0, 5, 2, 2012); // May 2, 2012
for ($i = 0; $i < $number_of_dates; $i++) {
   $date = strtotime('Wednesday +' . ($i * 2) . ' weeks', $startDate);
   echo date('m-d-Y', $date). "<br>".PHP_EOL;
}

See it in action.

Give it a date in the string, instead of "Wednesday" (that chooses the next Wednesday), write:

strtotime('20120502 +' . ($i * 2) . ' weeks'))

To choose that date. (Format is yyyymmdd).

If you have PHP 5.2.0 or newer, you can do it easily this way:

$date = new DateTime('2006-05-02');
for ($i=0; $i<10; $i++) {
   echo $date->format('m-d-Y').'<br/>'.PHP_EOL;
   $date->modify('+1 week');
}

You could also use the DatePeriod and DateInterval classes to make life easier.

Standard disclaimer: both of the classes above require PHP >= 5.3.0.

$number_of_dates = 10;

$start_date = new DateTime("5/2/12");
$interval   = DateInterval::createFromDateString("second wednesday");
$period     = new DatePeriod($start_date, $interval, $number_of_dates - 1);

foreach ($period as $date) {
    echo $date->format("m-d-Y") . "<br>" . PHP_EOL;
}