Hi guys
How can I create a array in this loop
PHP Code:$current = time();
for($i = 0; $i < 60; $i++){
$current = strtotime("+1 day", $current);
//// I want to create the array here
}
| SitePoint Sponsor |




Hi guys
How can I create a array in this loop
PHP Code:$current = time();
for($i = 0; $i < 60; $i++){
$current = strtotime("+1 day", $current);
//// I want to create the array here
}





Create an array of what, exactly?




thanks for the reply
The loop creates a list of the next 60 days
I need to pass it to a template file so need to put it in to a array

Do you mean this?
PHP Code:$current = time();
for($i = 0; $i < 60; $i++){
$current = strtotime("+1 day", $current);
$temp_array[] = $current;
echo"$current<br />";
}
echo '<pre>';
print_r($temp_array);




Thanks that worked
Now getting this error
Warning: strtotime() expects parameter 2 to be long, string given in
PHP Code:$current = time();
for($i = 0; $i < 60; $i++){
$current1 = strtotime("+1 day", $current);
$current = date("F j, Y, g:i a", $current1);
$temp_array[] = $current;
}
PHP Code:<?php
$iCurrent = time();
for($iDays = 0; $iDays < 60; $iDays++)
{
$aFinal[] = date('F j, Y, g:i a', $iCurrent += 86400);
}
print_r($aFinal);
/*
Array
(
[0] => April 13, 2009, 9:42 pm
[1] => April 14, 2009, 9:42 pm
[2] => April 15, 2009, 9:42 pm
[3] => April 16, 2009, 9:42 pm
[4] => April 17, 2009, 9:42 pm
[5] => April 18, 2009, 9:42 pm
[6] => April 19, 2009, 9:42 pm
[7] => April 20, 2009, 9:42 pm
[8] => April 21, 2009, 9:42 pm
[9] => April 22, 2009, 9:42 pm
[10] => April 23, 2009, 9:42 pm
[11] => April 24, 2009, 9:42 pm
[12] => April 25, 2009, 9:42 pm
[13] => April 26, 2009, 9:42 pm
[14] => April 27, 2009, 9:42 pm
[15] => April 28, 2009, 9:42 pm
[16] => April 29, 2009, 9:42 pm
[17] => April 30, 2009, 9:42 pm
[18] => May 1, 2009, 9:42 pm
[19] => May 2, 2009, 9:42 pm
[20] => May 3, 2009, 9:42 pm
[21] => May 4, 2009, 9:42 pm
[22] => May 5, 2009, 9:42 pm
[23] => May 6, 2009, 9:42 pm
[24] => May 7, 2009, 9:42 pm
[25] => May 8, 2009, 9:42 pm
[26] => May 9, 2009, 9:42 pm
[27] => May 10, 2009, 9:42 pm
[28] => May 11, 2009, 9:42 pm
[29] => May 12, 2009, 9:42 pm
[30] => May 13, 2009, 9:42 pm
[31] => May 14, 2009, 9:42 pm
[32] => May 15, 2009, 9:42 pm
[33] => May 16, 2009, 9:42 pm
[34] => May 17, 2009, 9:42 pm
[35] => May 18, 2009, 9:42 pm
[36] => May 19, 2009, 9:42 pm
[37] => May 20, 2009, 9:42 pm
[38] => May 21, 2009, 9:42 pm
[39] => May 22, 2009, 9:42 pm
[40] => May 23, 2009, 9:42 pm
[41] => May 24, 2009, 9:42 pm
[42] => May 25, 2009, 9:42 pm
[43] => May 26, 2009, 9:42 pm
[44] => May 27, 2009, 9:42 pm
[45] => May 28, 2009, 9:42 pm
[46] => May 29, 2009, 9:42 pm
[47] => May 30, 2009, 9:42 pm
[48] => May 31, 2009, 9:42 pm
[49] => June 1, 2009, 9:42 pm
[50] => June 2, 2009, 9:42 pm
[51] => June 3, 2009, 9:42 pm
[52] => June 4, 2009, 9:42 pm
[53] => June 5, 2009, 9:42 pm
[54] => June 6, 2009, 9:42 pm
[55] => June 7, 2009, 9:42 pm
[56] => June 8, 2009, 9:42 pm
[57] => June 9, 2009, 9:42 pm
[58] => June 10, 2009, 9:42 pm
[59] => June 11, 2009, 9:42 pm
)
*/
?>
@AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.




Just a note, arrays should be declared before being used in a loop:
PHP Code:$aFinal = array();
$iCurrent = time();
for ($iDays = 0; $iDays < 60; $iDays++) {
$aFinal[] = date('F j, Y, g:i a', $iCurrent += 86400);
}
// ...
Good practice? Indeed!
Required? Not really.
![]()
@AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.




Bookmarks