php 中foreach里面嵌套if判断怎么写
$relationship_html='';foreach($emplinfo['relationshipInfo']as$row){if($row['RELATIONS...
$relationship_html = '';
foreach ($emplinfo['relationshipInfo'] as $row) {
if($row['RELATIONSHIP_KEY'] == $family['RELATIONSHIP'])
$relationship_html .= '<option value="'.$row['RELATIONSHIP_KEY'].'" selected="selected">'.$row['RELATIONSHIP_NAME'].'</option>';
else
$relationship_html .= '<option value="'.$row['RELATIONSHIP_KEY'].'">'.$row['RELATIONSHIP_NAME'].'</option>';
} 展开
foreach ($emplinfo['relationshipInfo'] as $row) {
if($row['RELATIONSHIP_KEY'] == $family['RELATIONSHIP'])
$relationship_html .= '<option value="'.$row['RELATIONSHIP_KEY'].'" selected="selected">'.$row['RELATIONSHIP_NAME'].'</option>';
else
$relationship_html .= '<option value="'.$row['RELATIONSHIP_KEY'].'">'.$row['RELATIONSHIP_NAME'].'</option>';
} 展开
展开全部
//加上大括号就行了,你写的都差不多了
foreach ($emplinfo['relationshipInfo'] as $row) {
if ($row['RELATIONSHIP_KEY'] == $family['RELATIONSHIP']) {
$relationship_html .= '<option value="' . $row['RELATIONSHIP_KEY'] . '" selected="selected">' . $row['RELATIONSHIP_NAME'] . '</option>';
} else {
$relationship_html .= '<option value="' . $row['RELATIONSHIP_KEY'] . '">' . $row['RELATIONSHIP_NAME'] . '</option>';
}
}
追问
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: family
Filename: views/empl.php
Line Number: 11
//php代码报错
追答
这个是警告错误,可以忽略的,你遍历的那个数组是不是为空了,判断一下,为空就不遍历
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询