PHP code is not running before loop : <pre><code>&lt;?php
$date = '2017-08-22';
$year = substr($date, 0, 4);
$month = substr($date, 5, 2);
$day = substr($date, 8, 2);
?&gt;

&lt;select&gt;
&lt;?php
for ($i=1; $i &lt; 30; $i++) { ?&gt;
&lt;option value="&lt;?php echo $i; ?&gt;" &lt;?php if($day === $i){ echo "selected"; }; ?&gt;&gt;&lt;?php echo $i; ?&gt;&lt;/option&gt;
&lt;?php } ?&gt;

&lt;/select&gt;
</code></pre>

<p>the code is not executing because <code>substr</code> is not running before the for loop. the select should be selected on day 22 but it is not selecting anything. if i change <code>$day = 22;</code>, it works. how can i fix this with the substring?</p>
