如何在php中设置选择框默认值

<?php
$options = array('volvo'=>'Volvo', 'saab' =>'Saab', 'audi' => 'Audi' );
echo "<select name='sss'>
";
foreach ($options as $k=>$v) echo "<option value='$v' >$k</option>
";
echo "</select>
";
?>

Question:

how to make 'audi' as the default value instead of 'volvo'? I know we can set 'selected' in html, but how could i do it in this php script?

You could detect if the default value is the one you want and insert the HTML you already identified:

$defaultVal = 'Audi';
foreach ($options as $k=>$v) {
    $selected = ($v == $defaultVal) ? " selected='selected'" : "";
    echo "<option value='$v'$selected>$k</option>
";
}

I usually create a helper function for outputing selects

function showSelect($name, $options, $selected, $attr = array()){
    $str = "<select name='".$name.'"';
    foreach($attr as $name=>$val){
        $str.= " ".$name."='".$val."'";
    }
    $str.=">";
    foreach($options as $k=>$val){
        $str.= "<option value='".$val."'".($val==$selected?" selected='selected'":"").">".$k.'</option>';
    }
    $str.="</select>";
    return $str;
}

then to call just

echo showSelect("sss", $options, "audi", array("id"=>"manufacturer"));
Try this:

$options = array('volvo'=>'Volvo', 'saab' =>'Saab', 'audi' => 'Audi' );
$select_value = 'audi';

<select id="test" name="test">
<?php foreach($option as $row) {?>
    <option value="<?php echo $row?>" <?php echo (strcmp($select_value,$row)==0) ?"selected='selected":'' ?>><?php echo $row?></option>
  <?php } ?>
</select>