我在foreach密码字段中有一个字段需要使用星号,但它是在foreach构建中,我将输入类型更改为“密码但它们都会被更改。”
我尝试了这个,但没有骰子:
代码:
foreach($rows as $field => $label)
echo "<div class='field'><label for='$field'>$label</label>
<input id='$field' name='$field' type='text' value='".@$$field."'
size='25%' maxlength='65' /></div>\n";
我试过用这个:
if ($field == "password" ){
echo "<input id='$field' name='$field' type='password' value='".@$$field."'
size='25%' maxlength='65' /></div>\n"}
什么。有什么想法吗?
答案 0 :(得分:0)
试试这个。我把它放在if else声明里面。
$fields = [
'text' => 'text label',
'password' => 'pass label'
];
foreach ($fields as $field => $label) {
if ($field == "password" ){
echo "<div class='field'><label for='$field'>$label</label><input id='$field' name='$field' type='password' value=$field
size='25%' maxlength='65' /></div><br />";
} else {
echo "<div class='field'><label for='$field'>$label</label>
<input id='$field' name='$field' type='text' value=$field
size='25%' maxlength='65' /></div><br />";
}
}