我试图在IF语句中嵌入一个foreach语句,如下所示。我得到了一个意想不到的T_ELSE"在" ELSE"条款是。我错过了语法吗?
if ($user_ID == $row7[0]['wp_users.ID']){
foreach ($row7 as $result) {
echo "<br>" . $result['text'] . " <em>(by: <a
href=\"http://example.com/port?ID=$result[ID]\">" . $result['display_name']
. "</a>" . ")</em>" . "{" . ($user_ID == $row7[0]['wp_users.ID']) ?
" | <a href=\"http://example.com/edit?
text=$the_SID&cat=$result[category]\">Edit this text</a><br>" : '') . "}";
}
else {
foreach ($row7 as $result) {
echo "<br>" . $result['text'] . " <em>(by: <a
href=\"http://example.com/port?ID=$result[ID]\">" . $result['display_name']
. "</a>" . ")</em>";
}
}
答案 0 :(得分:1)
if ($user_ID == $row7[0]['wp_users.ID']) {
foreach ($row7 as $result) {
$verify= ' | <a href="http://example.com/edit? text=' . $the_SID . '&cat=' . $result[category] . '">Edit this text</a><br>';
$UserIdCorrect = ($user_ID == $row7[0]['wp_users.ID']) ? $verify : '';
echo '<br>' . $result['text'] . ' <em>(by: <a href="http://example.com/port?ID=$result[ID]">' . $result['display_name'] . '</a>' . ')</em>' . "{" . $UserIdCorrect . "}";
}
} else {
foreach ($row7 as $result) {
echo "<br>" . $result['text'] . " <em>(by: <a href=\"http://example.com/port?ID=$result[ID]\">" . $result['display_name']
. "</a>" . ")</em>";
}
}