[英]comparing array with int in PHP
I'm reading through the drupal_bootstrap code at: https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_bootstrap/7 to try to understand how to bootstrap drupal code. 我正在通过以下网址阅读drupal_bootstrap代码: https ://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_bootstrap/7以尝试了解如何引导drupal代码。 I have experience in other languages but not php. 我有其他语言的经验,但没有php。 This line of code below puzzles me, because $phases is an array, and everything else is int. 下面的这段代码使我感到困惑,因为$ phases是一个数组,而其他所有内容都是int。 What does it mean when it compares array with an int? 将数组与int比较时是什么意思?
while ($phases && $phase > $stored_phase && $final_phase > $stored_phase) {
$current_phase = array_shift($phases);
Thanks! 谢谢!
In php basic comparison, an array with elements== True
and an empty array== False
. 在php基本比较中,具有elements == True
和空array == False
数组。
array_shift()
reduce the size of array. array_shift()
减小数组的大小。
So, in your example, the loop reduce the size of $phases
until the $phases
is empty. 因此,在您的示例中,循环会减小$phases
的大小,直到$phases
为空。
(better: until $phases
is empty or one of the other conditions are False
) (更好:直到$phases
为空或其他条件之一为False
为止)
There is not a comparison between array and integer, the condition is: 数组和整数之间没有比较,条件是:
ARRAY IS NOT EMPTY AND INT > INT AND INT > INT. 数组不是空的和整数>整数和整数>整数。
Please note that there are a sort of incongruity in php type juggling comparison: 请注意,php 类型的杂耍比较中存在某种不一致性:
array() == False
'' == False
0 == False
but: 但:
'' == 0
array() != '' <------ !!!!
array() != 0 <------ !!!!
it does not compare array to int. 它不将数组与int比较。
the first part of the condition where it uses $phases
just checks that it has a value. 使用$phases
的条件的第一部分只是检查它是否具有值。
Definition of bootstrap in Computing: 引导在计算中的定义:
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. 一种通过一些初始指令将程序加载到计算机中的技术,该初始指令允许从输入设备引入其余程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.