Click here to get back home

array of year/months

 HomeNewsGroups | Search | About
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
array of year/months Bob Bedford 05-14-2008
Get Chitika Premium
Posted by Bob Bedford on May 14, 2008, 8:10 am
Please log in for more thread options
Hi all,

it's there any simple way to create an array of years and months dynamically
(2 loops) for an associative array ?
I've tried this so far: (having an error on last line with the "=>" sign.

$table = array();
for($i=2005;$i<=date('y');$i++){
$table = array_push($i=>array());
for($d=1;$d<=12;$d++)
$table[$i] = array_push($table,$i=>0);
}

What I need is to create a table wich will then be written and readed using
$table[$year][$month] = $somevalue;

Thanks for helping.



Posted by Erwin Moller on May 14, 2008, 8:48 am
Please log in for more thread options
Bob Bedford schreef:
> Hi all,
>
> it's there any simple way to create an array of years and months dynamically
> (2 loops) for an associative array ?
> I've tried this so far: (having an error on last line with the "=>" sign.
>
> $table = array();
> for($i=2005;$i<=date('y');$i++){
> $table = array_push($i=>array());
> for($d=1;$d<=12;$d++)
> $table[$i] = array_push($table,$i=>0);
> }
>
> What I need is to create a table wich will then be written and readed using
> $table[$year][$month] = $somevalue;
>
> Thanks for helping.
>
>

Hi,

$table = array();
for($i=2005;$i<=date('y');$i++){
for($d=1;$d<=12;$d++)
$table[$i][$d] = "somevalue";
}

Something like that?

Regards,
Erwin Moller

Posted by Bob Bedford on May 14, 2008, 8:52 am
Please log in for more thread options
Hi Erwin,

thanks for replying.

Reading is not a problem. I've a problem to "build" the associative array.

"Erwin Moller"
> Bob Bedford schreef:
>> Hi all,
>>
>> it's there any simple way to create an array of years and months
>> dynamically (2 loops) for an associative array ?
>> I've tried this so far: (having an error on last line with the "=>" sign.
>>
>> $table = array();
>> for($i=2005;$i<=date('y');$i++){
>> $table = array_push($i=>array());
>> for($d=1;$d<=12;$d++)
>> $table[$i] = array_push($table,$i=>0);
>> }
>>
>> What I need is to create a table wich will then be written and readed
>> using $table[$year][$month] = $somevalue;
>>
>> Thanks for helping.
>
> Hi,
>
> $table = array();
> for($i=2005;$i<=date('y');$i++){
> for($d=1;$d<=12;$d++)
> $table[$i][$d] = "somevalue";
> }
>
> Something like that?
>
> Regards,
> Erwin Moller
>



Posted by Erwin Moller on May 14, 2008, 9:05 am
Please log in for more thread options
Bob Bedford schreef:
> Hi Erwin,
>
> thanks for replying.
>
> Reading is not a problem. I've a problem to "build" the associative array.
>
> "Erwin Moller"
>> Bob Bedford schreef:
>>> Hi all,
>>>
>>> it's there any simple way to create an array of years and months
>>> dynamically (2 loops) for an associative array ?
>>> I've tried this so far: (having an error on last line with the "=>" sign.
>>>
>>> $table = array();
>>> for($i=2005;$i<=date('y');$i++){
>>> $table = array_push($i=>array());
>>> for($d=1;$d<=12;$d++)
>>> $table[$i] = array_push($table,$i=>0);
>>> }
>>>
>>> What I need is to create a table wich will then be written and readed
>>> using $table[$year][$month] = $somevalue;
>>>
>>> Thanks for helping.
>> Hi,
>>
>> $table = array();
>> for($i=2005;$i<=date('y');$i++){
>> for($d=1;$d<=12;$d++)
>> $table[$i][$d] = "somevalue";
>> }
>>
>> Something like that?
>>
>> Regards,
>> Erwin Moller
>>
>

Hi,

[Please don't toppost]

Can you give us an example of that targetarray?
eg:
[2005][1] = ...
[2005][2] = ...
???

It is not clear to me.
What is it you want as a result?
And where does the associative array come in?

Regards,
Erwin Moller

Posted by Erwin Moller on May 14, 2008, 9:08 am
Please log in for more thread options
Erwin Moller schreef:
> Bob Bedford schreef:
>> Hi Erwin,
>>
>> thanks for replying.
>>
>> Reading is not a problem. I've a problem to "build" the associative
>> array.
>>
>> "Erwin Moller"
>> écrit dans le message de news:
>> 482adfa6$0$14347$e4fe514c@news.xs4all.nl...
>>> Bob Bedford schreef:
>>>> Hi all,
>>>>
>>>> it's there any simple way to create an array of years and months
>>>> dynamically (2 loops) for an associative array ?
>>>> I've tried this so far: (having an error on last line with the "=>"
>>>> sign.
>>>>
>>>> $table = array();
>>>> for($i=2005;$i<=date('y');$i++){
>>>> $table = array_push($i=>array());
>>>> for($d=1;$d<=12;$d++)
>>>> $table[$i] = array_push($table,$i=>0);
>>>> }
>>>>
>>>> What I need is to create a table wich will then be written and
>>>> readed using $table[$year][$month] = $somevalue;
>>>>
>>>> Thanks for helping.
>>> Hi,
>>>
>>> $table = array();
>>> for($i=2005;$i<=date('y');$i++){
>>> for($d=1;$d<=12;$d++)
>>> $table[$i][$d] = "somevalue";
>>> }
>>>
>>> Something like that?
>>>
>>> Regards,
>>> Erwin Moller
>>>
>>
>
> Hi,
>
> [Please don't toppost]
>
> Can you give us an example of that targetarray?
> eg:
> [2005][1] = ...
> [2005][2] = ...
> ???
>
> It is not clear to me.
> What is it you want as a result?

[correction]
> And where does the associative array come in?
>

I ment: Where does the associative array come into the picture?

Another thing: You said my samplecode 'reads' the array.
It does not, it creates it.

Regards,
Erwin Moller

Similar ThreadsPosted
How do I pass an array key from a multi-dimensional array to a new array? February 18, 2008, 6:35 pm
Array (multidimensional) help - using array like SQL tables to get round lack of Union in MySQL3. April 20, 2005, 4:32 am
"Array to String Conversion" error when constructing a multi-dimensional array January 17, 2007, 3:42 am
HELP! Selecting Array Rows based on an array of field=>value s October 21, 2006, 9:20 pm
Finding elements of an array in another multi-dimensional array February 1, 2007, 5:35 am
Array caching and optimising the array manipulation process July 25, 2007, 6:26 pm
navigate multidimensional array with path in flat array October 18, 2007, 11:32 am
Vedere se due array sono lo stesso array September 16, 2005, 12:15 pm
Creative a regular array from associative array? March 7, 2006, 7:46 pm
create array from members of an array of objects February 7, 2007, 11:55 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap