date foreach array
<p>Why doesn't this work, its suppose to pick from the arrayed dates which the current date falls between. so for example if the date is <code>16-01-30</code> the date chosen would be <code>16-02-14</code> Thankyou for helping me.</p>

<pre><code>    &lt;?
    $date = array('16-01-14','16-01-28','16-02-14','16-02-28');
    $currentdate = date('y-m-d');
    echo $currentdate;
    ?&gt;
    &lt;form&gt;
    &lt;select&gt;
    &lt;?php
    foreach ($date as $i =&gt; $d) {
        if ($currentdate &gt;= $d &amp;&amp; ($i == count($date)-1 || $currentdate &lt; $date[$i+1])) {
            $selected = "selected";
        } else {
            $selected = "";
        }
        list($year, $month, $day) = explode('-', $d);
        echo "&lt;option $selected&gt;$month/$day/$year&lt;/option&gt;";
    }
    ?&gt;
    &lt;/select&gt;
    &lt;/form&gt;
</code></pre>