Jump to content

PHP Variables by reference


DarkMantis

Recommended Posts

You use references when you need to avoid the replication of variables.

 

Typically, when you pass a variable to a function, it is within the scope of that function only, and you must return the desired variable to get what you want your function to do.

 

When passing by reference, you are preserving the scope to that variable.  It's much like when you order something with Fedex.  When your package is received by Fedex, the don't go out and get a duplicate item to pass to the next branch.  They send YOUR package throughout all of the branches until it reaches your door.

 

If Fedex didn't "pass by reference", then your item would be received, put into a different box, perhaps even exchanged with a different yet similar item, and so on to each branch until it reached your door.  Hopefully that puts things into perspective.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.