|  | Posted by J.O. Aho on 04/15/07 05:04 
Vince Morgan wrote:> I'm new to php and often discover that what looks like an error to me in a
 > piece of code is in fact functionality that I was unaware of.
 > In another php forum today I came across the snip below.
 > I don't think it's appropriate to ask in that forum while the OP's question
 > had not yet been addressed.
 > The usage of the curly brackets is screwing with my head, most especialy the
 > last line.
 >
 > foreach (array($section, 'newImage', "${section}_width", "$
 > {section}_height") as $val)
 >  $this->$val =& ${$val};
 
 It's mainly used to tell what is a variable in a string, say you have a
 variable called $hell and you have the following
 
 echo "$hellohm's";
 
 this would try to use the variable $hellohm, which most likely would be an
 empty variable and result in a string: 's
 
 echo "{$hell}ohm's";
 
 this would use the value of $hell and add ohm's after the value.
 
 The brackets works outside string too, even if it's not that nice looking IMHO.
 
 In the last line ${$val} is the same as $$val, which makes that the value of
 $val is used as a variable name, say you
 
 $hello=5;
 $val="hello";
 echo $$val; //will echo the $hello value
 
 
 --
 
 //Aho
  Navigation: [Reply to this message] |