Jump to content

Associative Array?


Solarpitch

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.