views:

68

answers:

4
<?php
$salaries = array(1000,1500,2000,2500,3000,4000,5000,6000,7000,9000,12000,18000,30000);
$str = '';
foreach($salaries as $salary)
{
    $str .= "<option value=\"$salary\">$salary+</option>";
}

function populateSalary()
{
    $salaries = array(1000,1500,2000,2500,3000,4000,5000,6000,7000,9000,12000,18000,30000);
    $str = '';
    foreach($salaries as $salary)
    {
     $str .= "<option value=\"$salary\">$salary+</option>";
    }
    return $str;
}
?>
<select id="salaryExpect" name="salaryExpect">
    <option value="-1">--<option>
    <?php echo populateSalary(); ?>
</select>

See?There is no such empty option as <option> </option> in the code,but strange enough there is in the output.

Can have a look here: http://maishudi.com/test3.php

+8  A: 

This line

<option value="-1">--<option>

You're not closing the tag, you're opening another, it should read

<option value="-1">--</option>
Chad
Nice shot!
Shore
+2  A: 
<option value="-1">--<option>

is the error , change it to

<option value="-1">--</option>
Nettogrof
+1  A: 

In the line <option value="-1">--<option>, your close tag isn't actually closing. It should read:

<option value="-1">--</option>
Smashery
+1  A: 

Hello Shore, Please look carefully at the first "option" in the output, you forgot to close the tag :)

phunehehe