473,508 Members | 2,249 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

initial value in a month array

3 New Member
I have set up an array that includes the months of the year.

<?php
// define array
$month = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
// loop over it
// print array elements
foreach ($month as $a) {
echo '<br>'.$a;
}
?>

Is there a way to have this start with the current date?

I've seen date("m") used to pull the current date and have it set as the option value in a select box, but not in the array itself.

Any help would be greatly appreciated.
Sep 19 '06 #1
3 4927
pasupathi
5 New Member
use the function now() and try
Sep 20 '06 #2
jspot
3 New Member
This is the code I finally came up with.
Hope this helps someone else!

<?php
$month = array
('now -1 months',
'now -2 months',
'now -3 months',
'now -4 months',
'now -5 months',
'now -6 months',
'now -7 months',
'now -8 months',
'now -9 months',
'now -10 months',
'now -11 months',
'now -12 months');

foreach ($month as $a) {
$date=strtotime("$a");
$date=date("F",$date);
echo '<br>'.$date;
}
?>
Sep 20 '06 #3
jspot
3 New Member
Below is the code that will pull current month first. The previous example was a month behind.

<?php
$month = array
('now',
'now -1 months',
'now -2 months',
'now -3 months',
'now -4 months',
'now -5 months',
'now -6 months',
'now -7 months',
'now -8 months',
'now -9 months',
'now -10 months',
'now -11 months');

foreach ($month as $a) {
$date=strtotime("$a");
$date=date("F",$date);
echo '<br>'.$date;
}
?>
Sep 20 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2761
by: TekWiz | last post by:
I've got a system that automatically generates a form. I have it set up so that the backend will return to the inital form page with an error object in sessions data (assuming the backend detected...
4
4697
by: Porthos | last post by:
Hi All, I'm trying to find the minimum value of a set of data (see below). I want to compare the lengths of these attribute values and display the lowest one. This would be simple if I could...
9
2130
by: Gianni | last post by:
I have to insert in a html select the last 10 years <select name="year" onChange="month()" size=5> <option value="1994">1994</option> <option value="1995">1995</option> <option...
12
6970
by: Susan Cranford | last post by:
Please forgive, I have looked at so much info I can't figure out how to put it together even though I know it must be fairly simple. I have an array of input text boxes (txtDOBn) where n is...
2
1502
by: kaosyeti | last post by:
i have a report that tracks customer contacts by salespeople at a car dealership. the contacts are assigned several values, one of which is the date that they came in. the report is capeable of...
5
1975
by: ABC | last post by:
How to initial the datetime variable as value to "01/01/2005 00:00:00"?
6
5883
by: Aston Martin | last post by:
Hi All, ********************** My Situation ********************** I am working on project that involves passing a structure to unmanaged code from .Net world (well using C#). Perhaps an example...
2
5308
code green
by: code green | last post by:
On the first of each month I need to create a report from the previous month covering 1-15 and 16-end of month. I am using the following code which forms part of a mssql query and part of the...
1
1496
by: filippo nanni | last post by:
Hello, I have a new question about organizing multidimensional arrays. I have an array containing several others; my aim is to obtain a new array, which groups together those arrays from the first...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7383
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1557
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.