在条件语句中定义变量的操作是否有明确的名称?
Is there a definitive name for the action of defining a variable inside a conditional statement?
我认为这个问题相当简单,不仅适用于我,而且适用于整个 PHP 语言。
这是非常基础的,如果它确实有名字,那么在学习 PHP 时知道它叫什么并不重要。但是有些人,显然包括我在内,希望能够理解这些非常基本的问题。
我会用一个例子"if (conditional) statement"来说明这个问题。
if (!$result = mysqli_query($con, $sql)) {
echo 'FAILED';
}
正如您在此处看到的,mysqli_query 函数的结果存储在 $result 变量中,而函数和变量位于条件语句中。
这是我的问题,一如既往,感谢您的阅读,欢迎和感谢您的回答或批评。
此致,
开发者Dan
我不知道具体名称,但在 ExpressionsExpressions
部分的 PHP 文档中对其进行了描述
引用:
PHP takes expressions much further, in the same way many other languages do. PHP is an expression-oriented language, in the sense that almost everything is an expression. Consider the example we've already dealt with, '$a = 5'. It's easy to see that there are two values involved here, the value of the integer constant '5', and the value of $a which is being updated to 5 as well. But the truth is that there's one additional value involved here, and that's the value of the assignment itself. The assignment itself evaluates to the assigned value, in this case 5. In practice, it means that '$a = 5', regardless of what it does, is an expression with the value 5. Thus, writing something like '$b = ($a = 5)' is like writing '$a = 5; $b = 5;' (a semicolon marks the end of a statement). Since assignments are parsed in a right to left order, you can also write '$b = $a = 5'.
(重点是我的)
"The assignment itself evaluates to the assigned value",这就是为什么赋值本身可以作为 if
条件
进行测试的原因
我认为这个问题相当简单,不仅适用于我,而且适用于整个 PHP 语言。
这是非常基础的,如果它确实有名字,那么在学习 PHP 时知道它叫什么并不重要。但是有些人,显然包括我在内,希望能够理解这些非常基本的问题。
我会用一个例子"if (conditional) statement"来说明这个问题。
if (!$result = mysqli_query($con, $sql)) {
echo 'FAILED';
}
正如您在此处看到的,mysqli_query 函数的结果存储在 $result 变量中,而函数和变量位于条件语句中。
这是我的问题,一如既往,感谢您的阅读,欢迎和感谢您的回答或批评。
此致,
开发者Dan
我不知道具体名称,但在 ExpressionsExpressions
部分的 PHP 文档中对其进行了描述引用:
PHP takes expressions much further, in the same way many other languages do. PHP is an expression-oriented language, in the sense that almost everything is an expression. Consider the example we've already dealt with, '$a = 5'. It's easy to see that there are two values involved here, the value of the integer constant '5', and the value of $a which is being updated to 5 as well. But the truth is that there's one additional value involved here, and that's the value of the assignment itself. The assignment itself evaluates to the assigned value, in this case 5. In practice, it means that '$a = 5', regardless of what it does, is an expression with the value 5. Thus, writing something like '$b = ($a = 5)' is like writing '$a = 5; $b = 5;' (a semicolon marks the end of a statement). Since assignments are parsed in a right to left order, you can also write '$b = $a = 5'.
(重点是我的)
"The assignment itself evaluates to the assigned value",这就是为什么赋值本身可以作为 if
条件