doudu2404 2017-05-22 01:19
浏览 10
已采纳

PHP语法错误,意外'如果'(T_IF)[重复]

This question already has an answer here:

I want to make the text red if username == user_id but it gives me a syntax error, unexpected 'if' (T_IF). my code:

foreach ($dag as $taak) {
    echo '<li' if($_SESSION['user_id'] == $taak['username']){ echo 'style="color:red"';}'>'.$taak['taak_naam'].' - '.$taak['username'].'</li>';
}

anyone any idea?

</div>
  • 写回答

5条回答 默认 最新

  • dongsong73032 2017-05-22 01:22
    关注

    It should be something like this

    echo '<li';
    
    if($_SESSION['user_id'] == $taak['username']){ 
    
    echo ' style="color:red"';
    
    }
    
    echo '>'.$taak['taak_naam'] . ' - '  .$taak['username'] . '</li>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)
编辑
预览

报告相同问题?