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 ";
		}
	}
	?>

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. ;)

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.