Re: References and array indexes

From: Date: Thu, 05 Aug 2004 08:57:30 +0000
Subject: Re: References and array indexes
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-192817@lists.php.net to get a copy of this message
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, but for that I can't answer anymore ;) Ace

« previous php.general (#192817) next »