0

When trying to dynamically create a select box with values using php my data will not populate. All of the research I've done shows I've done this right. Can anyone point me to the right direction please.

<select name="month">
<?php
    $months = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

    for ($x=0; $x<=11; $x++) {
        echo '<option value="' . $x+1 . '">' . $months[$x] . '</option>';
    }
?>
</select>
laminatefish
  • 5,197
  • 5
  • 38
  • 70
seanr
  • 195
  • 1
  • 4
  • 10

1 Answers1

0

you should add parentheses around the $x+1

like so:

<select name="month">
<?php
    $months = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

    for ($x=0; $x<=11; $x++) {

        echo '<option value="' . ($x+1) . '">' . $months[$x] . '</option>';
    }
?>
</select>
itaynoy
  • 143
  • 8
  • you can read more about this here: http://stackoverflow.com/questions/7574624/arithmetic-operation-within-string-concatenation-without-parenthesis-causes-stra – itaynoy Sep 17 '14 at 20:14