Solarpitch Posted January 15, 2009 Share Posted January 15, 2009 Hey, I'm working with the following loop that will loop through a month and return each day in the month. <?php $date = mktime(0,0,0,3,1,$year); //The get's the first of March 2009 //$links = array(); for($n=1;$n <= date('t',$date);$n++){ echo $n; } //OUTPUT: 1 2 3 4 5 6 .... 31 ?> For each day in the loop I need to create an associative array which will be identical to. $data = array( 1 => 'http://example.com/news/article/2009/1/', 2 => 'http://example.com/news/article/2009/2/', 3 => 'http://example.com/news/article/2009/3/', ......... 31 => 'http://example.com/news/article/2009/31/' ); So something like this but not quite sure... <?php $date = mktime(0,0,0,3,1,$year); //The get's the first of March 2009 //$links = array(); for($n=1;$n <= date('t',$date);$n++){ $data = array( $n => 'http://example.com/news/article/2009/'.$n.'/'); } ?> Link to comment https://forums.phpfreaks.com/topic/140882-associative-array/ Share on other sites More sharing options...
.josh Posted January 15, 2009 Share Posted January 15, 2009 $data[$n] = 'http://example.com/news/article/2009/'.$n.'/'; fyi that's not an associative array. Associative arrays are where the keys are strings. Numbered keys are numeric arrays. Link to comment https://forums.phpfreaks.com/topic/140882-associative-array/#findComment-737387 Share on other sites More sharing options...
Solarpitch Posted January 15, 2009 Author Share Posted January 15, 2009 Ah I get ya! Thanks for that it sorted me out good! Link to comment https://forums.phpfreaks.com/topic/140882-associative-array/#findComment-737388 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.