View Single Post

  #2 (permalink)  
Old 05-12-2008
Piotr
 
Posts: n/a
Default Re: A question about php reference in array

hi and hello wrote:
> $i = array('data'=>1000);

Here you have created that array


> $arr = array('i'=>&$i);

Here you said something like:
create an array with a field named 'i', and let
the field contain a link to $i variable

> $arr2 = $arr;

Here you have made a copy of the array,
like the above one, it has the 'i' field,
and the field contains the same link

It's like a link in your file system, when you copy a link,
it does not copy the original file.


> $i['data'] = 200;

Here you changed the value, it;s lieke you would change
what the file (in the file system) contains

When you print the arrays, PHP searched for the $i variable,
that is referenced by both tables and prints the reference target value.
That is what the reference is ment to do.

You can find more here:
php.net/manual/pl/language.references.php
Check out the examples in comments given by people.

best regards
Piotr N
Reply With Quote