Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 887993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:19:15+00:00 2026-05-15T13:19:15+00:00

i thought, that i understand what references do. but now i meet an example,

  • 0

i thought, that i understand what references do.
but now i meet an example, which can’t understand anyway.

i saw an interesting script here, but why he use & in this script i can’t understand.
here is the part of script

foreach ($nodeList as $nodeId => &$node) 
{
    if (!$node['id_parrent'] || !array_key_exists($node['id_parrent'], $nodeList)) 
    {
        $tree[] = &$node;
    } 
    else 
    {
        $nodeList[$node['id_parrent']]['children'][] =&$node;
    }
}

if he doesn’t make any changes on $node, why it is needed to use references here?
there is nothing like $node = any changes, so why use =& $node, instead $node?

maybe you will help me to understand?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:19:15+00:00Added an answer on May 15, 2026 at 1:19 pm

    $tree[] = &$node;

    When you do it like this, the tree array will store references to the same nodes as in the node list. If you change a node from the node list, it will be changed in the tree too and vice-versa of course. The same applies to the children array.

    Without using references, the tree and children array would simply contain a copy of the node.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I thought that layout is just a widget that keeps more widgets inside. But
I must honestly say that I do not really understand much about casting, but
I'll ask this with a Scala example, but it may well be that this
I fully appreciate the atomicity that the Threading.Interlocked class provides; I don't understand, though,
After I thought that I've understood how they work, I tried this: NSString *str1
I thought that by convention, only methods with an exclamation mark altered the object.
I thought that a 32-bit process could use at most 2GB RAM, since half
I thought that a delegate instance was interchangeable with a function instance. Take the
I thought that by default my Regex would exhibit the greedy behavior that I
I thought that calling BeginInvoke more than once on the same delegate instance would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.