【问题标题】:I do not understand what this code is doing in PHP我不明白这段代码在 PHP 中的作用
【发布时间】:2012-06-03 12:29:31
【问题描述】:

我有这个代码,

// TEMP VAR
$temp = &$files;
// BUILD ARRAY STRUCTURE
while(count($file['path'])) {
    // GET DIRECTORY
    $directory = array_shift($file['path']);
    // DIRECTORY NOT SET
    if(!isset($temp[$directory])) {
        // SET DIRECTORY
        $temp[$directory] = array();
    }
    // GO INTO ARRAYS NEXT DIRECTORY
    $temp = &$temp[$directory];
}

我是从这个问题的答案中得到的,

String with array structure to Array

我知道它是做什么的,但不知道它是怎么做的,谁能给我逐行解释发生了什么?

谢谢大家。

【问题讨论】:

  • 具体哪一行,你不明白吗?您对每一行都有描述性注释...
  • -1 emilvikstrom.se/whyidownvote.html(你读过什么?你是这门语言的新手吗?你的目标是什么?)
  • @OliCharlesworth 我不明白& 在这两种情况下都在做什么,我知道这与reference 有关,但我查看了文档但仍然无法弄清楚。

标签: php


【解决方案1】:

在这种用法中的 & 符号是一个引用。见this article

$variable = 'Lorem ipsum';
$new = &$variable;
$variable = 'Some new data';
echo $new; //Prints "Some new data"

【讨论】:

    猜你喜欢
    • 2012-09-01
    • 1970-01-01
    • 2017-06-14
    • 2021-11-03
    • 1970-01-01
    • 2014-06-12
    • 2012-05-25
    • 2010-12-14
    • 1970-01-01
    相关资源
    最近更新 更多