将变量添加到三元运算符 Php
add variable to ternary operator Php
我想总结这个三元运算符并向结果添加一个新变量(在一行中)
$names= "Joe";
$channel ="joe";
$user_alt= $names ? $names : "";
$user_alt= $user_alt." @".$channel;
预期结果
<img src="" alt="Joe @joe" />
我想你想做的是:
$user_alt= ($names ? $names : "") ." @".$channel;
请注意三元运算符周围括号的必要性,因为 :
的优先级低于 .
。
我想总结这个三元运算符并向结果添加一个新变量(在一行中)
$names= "Joe";
$channel ="joe";
$user_alt= $names ? $names : "";
$user_alt= $user_alt." @".$channel;
预期结果
<img src="" alt="Joe @joe" />
我想你想做的是:
$user_alt= ($names ? $names : "") ." @".$channel;
请注意三元运算符周围括号的必要性,因为 :
的优先级低于 .
。