Forum Moderators: coopster

Message Too Old, No Replies

Newbie ARRAY question

How can i make this an array....

         

tonynoriega

3:53 pm on Aug 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



i know there is an easier way, but im new, so im asking for assistance, not just the answer, but also a "lehmans" terms of what and why...?

Its basically just a way to display a weeks calendar, from the current day, back 7 days....
not the first three variables, but the weekly days below..

$ts = time(); //current timestamp
$sdate = date("F j Y"); //start date
$edate = date("F j Y", ( $ts - $one_week)); //7 days ago
<!--this below is what i want to learn how to turn into an array-->
$one_week = 7 * 24 * 60 * 60; //seconds of 7 days ago
$six_days = 6 * 24 * 60 * 60; //seconds of 6 days ago
$five_days = 5 * 24 * 60 * 60; //etc.
$four_days = 4 * 24 * 60 * 60;
$three_days = 3 * 24 * 60 * 60;
$two_days = 2 * 24 * 60 * 60;
$one_day = 1 * 24 * 60 * 60;

eelixduppy

4:03 pm on Aug 14, 2007 (gmt 0)



Maybe something like this:
]
$seconds_in_day = 24*60*60;
$times = [url=http://www.php.net/array]array[/url]();
for($i = 1; $i <= 7; $i++) {
$times[] = $i*$seconds_in_day;
}
echo '<pre>'; print_r($times); echo '</pre>';

jatar_k

4:05 pm on Aug 14, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you just want an array of the last seven days in F j y format?

<? 
$datearr = array();
$counter = 0;
while ($counter < 7) {
$datearr[] = date("F j Y",strtotime("-$counter day"));
$counter++;
}
echo '<pre>';
print_r($datearr);
echo '</pre>';
?>

eelixduppy

4:10 pm on Aug 14, 2007 (gmt 0)



hehe - nice jatar :)