doushifang4382 2016-01-30 01:33
浏览 98
已采纳

在PHP中将数组与int进行比较

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. I have experience in other languages but not php. This line of code below puzzles me, because $phases is an array, and everything else is int. What does it mean when it compares array with an int?

while ($phases && $phase > $stored_phase && $final_phase > $stored_phase) {
      $current_phase = array_shift($phases);

Thanks!

  • 写回答

2条回答 默认 最新

  • dsf1222 2016-01-30 01:45
    关注

    In php basic comparison, an array with elements==True and an empty array==False.
    array_shift() reduce the size of array.

    So, in your example, the loop reduce the size of $phases until the $phases is empty.
    (better: until $phases is empty or one of the other conditions are False)

    Edit:

    There is not a comparison between array and integer, the condition is:
    ARRAY IS NOT EMPTY AND INT > INT AND INT > INT.

    Edit 2:

    Please note that there are a sort of incongruity in php type juggling comparison:

    array() == False
    ''      == False
    0       == False
    

    but:

    ''      == 0
    array() != ''   <------ !!!!
    array() != 0    <------ !!!!
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?