$carmakers
包含cars的名称,这是数组中制造商的值之一。
令我感到不安的是,即使$carmakers
变量不为空,也不会出现这种情况?
<?php
if($val->title == $carmakers){ echo 'selected = "selected"' ; }
?>
我的完整代码是:
<?php foreach ($carmake as $key1 => $carmakers):?>
<select name="maker[]" class="car_make " >
<?php if (empty($carmakers)): ?>
<option>Please Select Car Option</option>
<?php endif; ?>
<?php foreach ($maker as $key => $val): ?>
<option value="<?php echo $val->title; ?> "
<?php if($val->title == $carmakers){ echo 'selected = "selected"' ; }?> >
<?php echo strtoupper($val->title); ?>
</option>
<?php endforeach; ?>
</select>
<?php endforeach;?>
答案 0 :(得分:1)
你的foreach循环似乎是错误的..它应该看起来像这样......
foreach ($carmakers as $key => $carmake)
你的看起来像这样......
foreach ($carmake as $key => $carmakers)