<?php
$date = '2017-08-22';
$year = substr($date, 0, 4);
$month = substr($date, 5, 2);
$day = substr($date, 8, 2);
?>
<select>
<?php
for ($i=1; $i < 30; $i++) { ?>
<option value="<?php echo $i; ?>" <?php if($day === $i){ echo "selected"; }; ?>><?php echo $i; ?></option>
<?php } ?>
</select>
the code is not executing because substr
is not running before the for loop. the select should be selected on day 22 but it is not selecting anything. if i change $day = 22;
, it works. how can i fix this with the substring?