我是 php 开发的新手,我正在努力编写一个代码来检查条件以在下拉列表中设置选定的值
while ($row = $result_departments->fetch_assoc()) {
$dept_info = array(
'name' => $row['dpt_name'],
'id' => $row['dpt_id']
);
$departments.= '<option value="'.$dept_info['name'].'" name="'.$dept_info['name'].'">'.$dept_info['name'].'</option>';
}
return $departments;
在填充 $departments 时我想添加条件if $dept_info['name']=="XYZ" selected=="selected"
怎么做?我无法编写正确的语法。