Creating Drop-down Menu based on Current Date

Program:- Creating Drop-down Menu based on Current Date. You want to create a series of drop down menus that are based automatically on the current date.

Solution – Creating Drop-down Menu based on Current Date

<?php 
$options = array();
$when = new DateTime();
for ($i = 0; $i < 7; ++$i) {
	$options[$when->getTimestamp()] = $when->format("D, F j,Y");
	$when->modify("+1 day");
}
?>

 <select name="" id="">
 	<?php 
 	foreach ($options as $value=>$label) {
		print "<option value='$value'>$label</option>\n";
	}
 	 ?>
 </select>

 

Be the first to comment

Leave a Reply

Your email address will not be published.


*