3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function select_ts_hour($ts=NULL, $var='hour', $offset_day=0){ if (empty($ts)) { $ts = mktime(0,0,0,date("m"),date("d")+$offset_day,date("Y")); } $selected = date("H",$ts); select_hour($selected, $var); } function select_hour($selected=NULL, $var='hour'){ echo '<select name="'.$var.'" id="'.$var.'">'; for($i=0;$i<=23;$i++){ echo '<option value="'.substr($i+100,1).'"'; if ($selected == substr($i+100,1)) { echo ' selected="selected" '; } echo '>'.substr($i+100,1).'</option>'; } echo '</select>'; } echo select_ts_hour('1398441600', 'started_hour');
Output for 4.3.0 - 7.1.0
<select name="started_hour" id="started_hour"><option value="00">00</option><option value="01">01</option><option value="02">02</option><option value="03">03</option><option value="04">04</option><option value="05">05</option><option value="06">06</option><option value="07">07</option><option value="08">08</option><option value="09">09</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18" selected="selected" >18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option></select>