Re: php: assignment operator

From: Date: Wed, 07 Aug 2002 00:37:28 +0000
Subject: Re: php: assignment operator
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-111457@lists.php.net to get a copy of this message
In article <20020806235111.47963.qmail@pb1.pair.com>, tony@gonefishingguideservice.com says... > Thank you. > > I have another question regarding the same script. > > In the original code from Wrox "Beginning PHP4" on page 330, they use the > assignment operator .= > ............................ > > for($i=0; $i<strlen($counter); $i++) > { > $image_src=$image_dir. "/" .substr($counter, $i, 1) . ".jpg"; > $image_tag_src.="<IMG SRC=\"$image_src\" BORDER=\"0\">"; > // assignment > operator .= > } > .................................... > > why is that? > > If I was to assign the html string to the variable $image_tag_src without > the .= and insert a =, the script continues to run fine since $image_src > still contiunes to hold the value of > $image_dir. "/" .substr($counter, $i, 1) . ".jpg"; > > as in... > > ................................ > for($i=0; $i<strlen($counter); $i++) > { > $image_src=$image_dir. "/" .substr($counter, $i, 1) . ".jpg"; > $image_tag_src="<IMG SRC=\"$image_src\" BORDER=\"0\">"; > // assignment > operator = > } Simple difference .= will append to the existing variable whereas = will replace the content of the existing variable. -- David Robley Temporary Kiwi! Quod subigo farinam

« previous php.general (#111457) next »