views:

37

answers:

1

Hi, i used always $text = $datasql[0]; where $datasql = array('0'=>array('some'=>'text', 'some2'=>'text2'), '1'=>$data, etc...);

and found work costruction $datasql = &$datasql[0]; and work, why? That really reference?? and how remeber php in memory this solution.

Thanks for reaply

A: 

Every variable is a reference to a value. Normally the value is copied when you use it, but with & the reference is copied.

Suppose you have the following variable:

$original = 'john';

If you assign the value from $datasql to a variable, that value is copied:

$text = $original;

If you assign a reference, the value is not copied but referenced:

$text = & $original;

This means that $text points to the value of $original. Now, if you unset $original, the contents of $text are still valid:

unset($original);
echo $text; // john

This is because PHP knows there is still a reference to the value of $original, so it deletes the $original variable as name, but not the contents.

Your example is similar, except that the variable is not explicitly unset, but overwritten. It is a reference to a value, just like any other variable.

Sjoerd