Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我写了这段代码 <p>{{ $name or 'hello' }}</p>,但它只返回 1。我读到,它是 Laravel 5.7 中使用的语法,而不是更高版本,并将我的代码更改为 this <p>{{ $name ?? 'hello' }}</p>。但是这段代码什么也没返回。请帮帮我。
<p>{{ $name or 'hello' }}</p>
<p>{{ $name ?? 'hello' }}</p>
改用三元运算符
<p>{{ $name ?: 'hello' }}</p>
??是null合并运算符,在您的情况下$name不是 null 而是空字符串。
??
$name
https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary