如何在两个时期内检索每个日期的数组

I have two epochs. I want to figure out all the dates that are valid within the two epochs.

For example, if I have the epochs 946684800 (Sat, 01 Jan 2000 00:00:00 GMT) and 947203200 (Fri, 07 Jan 2000 00:00:00 GMT), I want to be able to get: 01/01/2000, 02/01/2000, 03/01/2000, 04/01/2000, etc.

PHP time values are just Unix timestamps - seconds since Jan 1/1970. Going off PHP 5's datetime object:

$start = strtotime('01 Jan 2000');
$end = strtotime('07 Jan 2000');

for ($d = $start; $d <= $end; $d += 86400) { // increment by 86,400 seconds, aka 1 day
    echo date('d/m/Y', $d);
}

There's better ways of going about it, using the DateTime / DateInterval objects, but this is just to show the basics.

Given that your epoch is in seconds you could always add the number of seconds found in a day to the first epoch:

 946684800 + 86400 = 946771200 -> Sun, 02 Jan 2000 00:00:00 GMT

And go on like this, I explain better:

947203200 - 946684800 = 518400 / 86400 = 6 (exactly 6 days)

so (PSEUDOCODE):

for(int i = 946684800; i<946684800 ;i+=86400){
    day = getDate(i);
}

If you have PHP 5.3 or newer, you could do this:

$date1 = new DateTime;
$date1->setTimestamp(946684800);

$date2 = new DateTime;
$date2->setTimestamp(947203200);

$interval = new DateInterval('P1D');

while ( $date1 <= $date2 )
{
  $dates_in_between[] = $date1->getTimestamp();
  $date1->add($interval);
}

Alternatively, you could use this:

// 1 day = 60 seconds * 60 minutes * 24 hours = 86400
for ($date = 946684800; $date <= 947203200; $date += 86400)
  $dates_in_beteween[] = $date;

$dates_in_between will contain a list of "dates" in between.

$epoch1 = '946684800';
$epoch2 = '947203200';
$i = 0;
while($time < $epoch2) {
    $time = mktime(0, 0, 0, date("m", $epoch1)  , date("d", $epoch1)+$i, date("Y",$epoch1));
    echo date('d/m/Y', $time)."<br>";
    $i++;
}

If understanding the question right, you want every DAY within the 2 epochs (2000-01-01 and 2000-01-07)..

Can be done like so:

<?php
$epoch1 = 946684800;
$epoch2 = 947203200;
$difference = $epoch1 - $epoch2;
..
//count days
$amountOfDays = round(($epoch2-$epoch1)/86400);

//looping all days
for($i=1; $i<=$amountOfDays; $i++) {
echo date('d/m/Y', $epoch1+($i*86400);
}
?>
$start = strtotime('2011-06-01');
$end = strtotime('2011-06-15');
$date = $start;
$anArray = array();

while ($date <= $end) {
    $date = strtotime("+1 DAY", $date);
    $anArray[] = $date;
}