我有以下代码一直给我一个"意想不到的其他"错误。有没有人看到我错过的那些顶着语法的东西?
<?php
$salesman = json_decode($invoice['salesman'], true);
if(empty($salesman)){
for($i = 1; $i <= 5; $i++) {
echo '<input type="checkbox" name="data-invoice-salesman[]" value="'.$i.'"/> '.$i.'<br>';
} else {
foreach($salesman as $k => $v) {
$i = $k+1;
if($v == "checked" {
echo '<input type="checkbox" name="data-invoice-salesman[]" value="'.$i.'" checked/> '.$i.'<br>'; // if checked, check.
} else {
echo '<input type="checkbox" name="data-invoice-salesman[]" value="'.$i.'"/> '.$i.'<br>'; // if not checked, don't check.
}
}
}
答案 0 :(得分:3)
for($i = 1; $i <= 5; $i++){
echo '<input type="checkbox" name="data-invoice-salesman[]" value="'.$i.'"/> '.$i.'<br>';
for循环后你缺少}
。
更正后的代码:
<?php
$salesman = json_decode($invoice['salesman'], true);
if (empty($salesman)){
for($i = 1; $i <= 5; $i++){
echo '<input type="checkbox" name="data-invoice-salesman[]" value="'.$i.'"/> '.$i.'<br>';
}
} else {
foreach($salesman as $k => $v){
$i = $k+1;
if ($v == "checked") {
echo '<input type="checkbox" name="data-invoice-salesman[]" value="'.$i.'" checked/> '.$i.'<br>'; // if checked, check.
} else {
echo '<input type="checkbox" name="data-invoice-salesman[]" value="'.$i.'"/> '.$i.'<br>'; // if not checked, don't check.
}
}
}
你在if条件中$v == "checked"
之后也错过了')'。修正了你的问题。