-5

I have this code,

// 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];
}

I got it from the answer to this question,

String with array structure to Array

I know what it does, but not how it does it, could anyone please explain to me line by line what is happening?

Thank you all.

Community
  • 1
  • 1
hadley
  • 621
  • 3
  • 7
  • 12
  • 1
    Which line, specifically, don't you understand? You have a descriptive comment on every single line... – Oliver Charlesworth Jun 03 '12 at 12:31
  • -1 http://www.emilvikstrom.se/whyidownvote.html (What have you read? Are you new to the language? What is your goal?) – Emil Vikström Jun 03 '12 at 12:33
  • @OliCharlesworth I do not understand what the `&` is doing on both occasions, I know it something to do with `reference` but I looked at the docs and still can't figure it out. – hadley Jun 03 '12 at 12:37

1 Answers1

0

An ampersand in this use is a reference. See this article

$variable = 'Lorem ipsum';
$new = &$variable;
$variable = 'Some new data';
echo $new; //Prints "Some new data"
Steve Robbins
  • 13,672
  • 12
  • 76
  • 124