* Thus wrote Ace: > Gabriel Birke <birke <at> kontor4.de> writes: > > > > > Hello! > > > > The following PHP code: > > <? > > $a = array("1"=>"First Element", "2"=>"Second Element"); > > $v = &$a['3']; > > print_r($a); > > ?> > > has this result: > > > > Array( > > 1 => First Element, > > 2 => Second Element, > > 3 => > > ) > > > > Can anyone give me an explanation for this? What is happening in the > > guts of the PHP interpreter when it gets these instructions? > > > > With best regards > > > > Gabriel Birke > > > > Hi ! > > As you passed $a in reference while defining $v, the '3' index of $a was > defined. Furthermore, you didn't at any time affect a value to that '3' index > of $a, but it exists because he was invocated once... > > So the result of your print_r isn't odd ;) > > Maybe you know that very well and your question was infinitely more technical, To expand a little further...
the reason why $a['3'] needs to be created is because a reference *has* to point to something. So php will automatically make a blank variable for $a['3'] then assign the reference of $a['3'] to $v. If it was a normal assignment, PHP simply will throw an E_NOTICE letting you know that you're accessing an undefined variable. Then create an blank variable that is assign to $v. The array() will remain unchanged. Curt -- First, let me assure you that this is not one of those shady pyramid schemes you've been hearing about. No, sir. Our model is the trapezoid! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php