如果PHP if-else语句抛出语法错误意外

时间:2015-03-25 15:10:47

标签: php if-statement laravel

我有一个相当复杂的if-else语句,我需要帮助。

我只想检查Session中是否有值,如果是,则输出一个名为“alert-important”的字符串,该字符串将作为未来更改的钩子。

不起作用的部分是带有if语句的第二部分。

<div class="alert alert-{{ Session::get('flash_notification.level') . ' worksfine ' . if(Session::has('flash_notification.important') ? 'alert-important' : '') }} ">

我收到错误

"syntax error, unexpected 'if' (T_IF)"

2 个答案:

答案 0 :(得分:1)

这将是三元组,所以它应该是

(Session::has('flash_notification.important') ? 'alert-important' : '')

答案 1 :(得分:1)

看起来这句话是罪犯

if(Session::has('flash_notification.important')

速记if/else statements不使用if关键字。这是正确的方法:

(Session::has('flash_notification.important')

相关问题