将数组与 PHP 中的 int 进行比较
comparing array with int in PHP
我正在阅读位于 https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_bootstrap/7 的 drupal_bootstrap 代码,试图了解如何 bootstrap drupal 代码。我有使用其他语言的经验,但没有 php。下面这行代码让我很困惑,因为 $phases 是一个数组,而其他一切都是 int。比较数组和整数是什么意思?
while ($phases && $phase > $stored_phase && $final_phase > $stored_phase) {
$current_phase = array_shift($phases);
谢谢!
它不比较数组和整数。
它使用 $phases
的条件的第一部分只是检查它是否具有值。
计算中 bootstrap 的定义:
a technique of loading a program into a computer by means of a few
initial instructions which enable the introduction of the rest of the
program from an input device.
在php基本比较中,一个有元素的数组==True
和一个空数组==False
.
array_shift()
减小数组的大小。
因此,在您的示例中,循环减小了 $phases
的大小,直到 $phases
为空。
(更好:直到 $phases
为空或其他条件之一为 False
)
编辑:
没有数组和整数比较,条件是:
数组不为空 AND INT > INT AND INT > INT.
编辑 2:
请注意 php type juggling 比较中存在某种不协调:
array() == False
'' == False
0 == False
但是:
'' == 0
array() != '' <------ !!!!
array() != 0 <------ !!!!
我正在阅读位于 https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_bootstrap/7 的 drupal_bootstrap 代码,试图了解如何 bootstrap drupal 代码。我有使用其他语言的经验,但没有 php。下面这行代码让我很困惑,因为 $phases 是一个数组,而其他一切都是 int。比较数组和整数是什么意思?
while ($phases && $phase > $stored_phase && $final_phase > $stored_phase) {
$current_phase = array_shift($phases);
谢谢!
它不比较数组和整数。
它使用 $phases
的条件的第一部分只是检查它是否具有值。
计算中 bootstrap 的定义:
a technique of loading a program into a computer by means of a few initial instructions which enable the introduction of the rest of the program from an input device.
在php基本比较中,一个有元素的数组==True
和一个空数组==False
.
array_shift()
减小数组的大小。
因此,在您的示例中,循环减小了 $phases
的大小,直到 $phases
为空。
(更好:直到 $phases
为空或其他条件之一为 False
)
编辑:
没有数组和整数比较,条件是:
数组不为空 AND INT > INT AND INT > INT.
编辑 2:
请注意 php type juggling 比较中存在某种不协调:
array() == False
'' == False
0 == False
但是:
'' == 0
array() != '' <------ !!!!
array() != 0 <------ !!!!