Jump to content

Arrays and Functions: Is there a better way?


morocco-iceberg

Recommended Posts

Just wondering if there's a better/neater way to do this?

 

       <?php
	$a=array("February");
	$b=array("April","June","September","November");
	$c=array("January","March","May","July","August","October","December");
	echo $c[0];
	to();
	echo "<br/>";
	echo $a[0];
	te();
	echo "<br/>";
	echo $c[1];
	to();
	echo "<br/>";
	echo $b[0];
	t();
	echo "<br/>";
	echo $c[2];
	to();
	echo "<br/>";
	echo $b[1];
	t();
	echo "<br/>";
	echo $c[3];
	to();
	echo "<br/>";
	echo $c[4];
	to();
	echo "<br/>";
	echo $b[2];
	t();
	echo "<br/>";
	echo $c[5];
	to();
	echo "<br/>";
	echo $b[3];
	t();
	echo "<br/>";
	echo $c[6];
	to();
	echo "<br/>";

	function te(){
		$counter=0;
		while($counter<28){	
			$counter=$counter+1;
			echo " $counter ";
		}
	}
	function t(){
		$counter=0;
		while($counter<30){	
			$counter=$counter+1;
			echo " $counter ";
		}
	}
	function to(){
		$counter=0;
		while($counter<31){	
			$counter=$counter+1;
			echo " $counter ";
		}
	}
	?>

Link to comment
Share on other sites

Ouch... that was ugly lol. No offense. :P

 

for ($m = 1; $m <= 12; $m++) {
     $time = mktime(0, 0, 0, $m, 1, date('Y'));
     $days = date('t', $time);
     $month = date('F', $time);
     echo sprintf("%s - %d<br />", $month, $days);
}

 

Try that. Not tested though.

 

Edit - you may need to add something to it to duplicate the effect. Just to get you started. ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.