【发布时间】:2020-01-17 01:39:56
【问题描述】:
看看这段代码:
if ($the_string = a_function_call('someid123') && $another_string = another_function_call('someid123'))
{
// $the_string and $another_string are now both expected to be the values returned from their respective functions, and this block of code is expected to be run if both of them are not "falsey".
}
不过……
if ($the_string = a_function_call('someid123') && $another_string = another_function_call('someid123'))
{
// $the_string is now actually a boolean true. Not sure about $another_string.
}
这是一个奇怪的错误吗?还是预期的行为?我一直认为这就像第一个场景一样,并且我一直按照这个假设进行编码。
【问题讨论】:
-
&&运算符将返回真或假(布尔值)。 -
听不懂,它们看起来一样
-
你的意图是什么?测试
a_function_call的返回值?如果你想要返回值,用括号括起来 -
@Viney 不同的是注释,而不是代码。
标签: php