8 Replies - 59571 Views - Last Post: 14 February 2005 - 12:59 PM Rate Topic: -----

#1 SpaceMan  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 10
  • View blog
  • Posts: 507
  • Joined: 20-February 03

Month Array

Posted 14 February 2005 - 12:10 PM

how do i get this to display the names?

$month_names = array("January","February","March","April","May","June","July","August","September","October","November","December");
	function showThisMonthNames(){
  for($i=1;$i<13;$i++)
 	 echo ''. $month_names[$i] . '';
  $count = 1;
  for($i=1;$i<=$month_names;$i++){
 	 echo ' ' . $month_names[$i] . ' ';
 	 $count++;
  }
  }



Is This A Good Question/Topic? 0
  • +

Replies To: Month Array

#2 SoLi  Icon User is offline

  • andydust.com

Reputation: 41
  • View blog
  • Posts: 1,438
  • Joined: 27-January 02

Re: Month Array

Posted 14 February 2005 - 12:16 PM

edit: n/m i know nothing

This post has been edited by SoLi: 14 February 2005 - 12:17 PM

Was This Post Helpful? 0
  • +
  • -

#3 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Month Array

Posted 14 February 2005 - 12:22 PM

$month = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "Novemeber", "December");
foreach($month as $monthname)
{
   echo $monthname;
}


Was This Post Helpful? 0
  • +
  • -

#4 SpaceMan  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 10
  • View blog
  • Posts: 507
  • Joined: 20-February 03

Re: Month Array

Posted 14 February 2005 - 12:34 PM

Amadeus, on Feb 14 2005, 12:22 PM, said:

$month = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "Novemeber", "December");
foreach($month as $monthname)
{
   echo $monthname;
}


awesome,

thx
Dave
Was This Post Helpful? 0
  • +
  • -

#5 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Month Array

Posted 14 February 2005 - 12:40 PM

Also, for the first example, for a function to run, it must be called in the code, for example:
function showThisMonthNames($month_names){
 for($i=1;$i<13;$i++)
  echo ''. $month_names[$i] . '';
 $count = 1;
 for($i=1;$i<=$month_names;$i++){
  echo ' ' . $month_names[$i] . ' ';
  $count++;
 }
 }
$month_names = array("January","February","March","April","May","June","July","August","September","October","November","December");
showThisMonthNames($month_names);


As an additional point, you may want to check the looping code, I belive it may result in an endless loop, as $month_names is an array, and cannot be used as an integer variable for loop control.
Was This Post Helpful? 0
  • +
  • -

#6 SpaceMan  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 10
  • View blog
  • Posts: 507
  • Joined: 20-February 03

Re: Month Array

Posted 14 February 2005 - 12:43 PM

hmm,that works, but,

was trying to make it do numeric value and display the month name.

i tryed a few things to no avial.

<select name="month">
	<option value=""></option>
<?php
	for($m=1;$m<=12;$m++)
 	 echo '<option value="'.$m.'">'.$m.'</option>';
?>

</select>

Was This Post Helpful? 0
  • +
  • -

#7 SpaceMan  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 10
  • View blog
  • Posts: 507
  • Joined: 20-February 03

Re: Month Array

Posted 14 February 2005 - 12:45 PM

just saw your second post, looking
Was This Post Helpful? 0
  • +
  • -

#8 SpaceMan  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 10
  • View blog
  • Posts: 507
  • Joined: 20-February 03

Re: Month Array

Posted 14 February 2005 - 12:57 PM

Amadeus, on Feb 14 2005, 12:40 PM, said:

Also, for the first example, for a function to run, it must be called in the code, for example:
function showThisMonthNames($month_names){
 for($i=1;$i<13;$i++)
  echo ''. $month_names[$i] . '';
 $count = 1;
 for($i=1;$i<=$month_names;$i++){
  echo ' ' . $month_names[$i] . ' ';
  $count++;
 }
 }
$month_names = array("January","February","March","April","May","June","July","August","September","October","November","December");
showThisMonthNames($month_names);


As an additional point, you may want to check the looping code, I belive it may result in an endless loop, as $month_names is an array, and cannot be used as an integer variable for loop control.

got it thx

function showThisMonthNames($month_names){
	echo '<select name="month">';
  echo '<option value=""></option>';
for($i=1;$i<13;$i++){
 	 echo '<option value="'.$i.'">'. $month_names[$i] . '</option>';
}
	echo '</select>';

}
$month_names = array("January","February","March","April","May","June","July","August","September","October","November","December");



Was This Post Helpful? 0
  • +
  • -

#9 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Month Array

Posted 14 February 2005 - 12:59 PM

$month_names = array("January","February","March","April","May","June","July","August","September","October","November","December");
for($i=1;$i<=12;$i++)
{
   echo "Value is: ".$i." and Display is: ".$month_names[$i]."<br>";
}


[edit]Sorry, didn't see you last post.[\edit]

This post has been edited by Amadeus: 14 February 2005 - 01:43 PM

Was This Post Helpful? 1

Page 1 of 1