Jump to content

combine 2 variables


cinek

Recommended Posts

is it possible to combine 2 variables into one?I want a value of 1 variable and a value of 2nd variable, combined into 1 variable name which should contain a 3rd variableI tried this, but it doesn't work ;/$var1.$var2 = $var3

Link to comment
Share on other sites

Is something like this what you're after:Where:$var1 = "var";$var2 = "Name";doing:$$var1$var2 = "new variable";is the same as:$varName = "new variable";If that doesn't help you, could you explain a little more?EDIT: Fixed my syntax a little. Had some minor errors.EDIT2: Hmm...apparently I have my syntax way off. I can't get this to work...I know there's a way to do it..........:)

Link to comment
Share on other sites

basically I need to get an image height of all divs which go through a loop. I count the no of times the loop goes around - and save it to $var2. The height of the image, is set in var $heightnow, to be able to use this, I need to create a 3rd variable $var3 and combine the name $var3 with the data from $var2so e.g. loop goes around once = $imageHeight1 = $heighttwice = $imageHeight2 = $height (new var $imageHeight + data from $var2 =old var $height)etc etc

Link to comment
Share on other sites

Ah-ha, the key is to use the dot operator like this:$varName = "varVar";${'test'.$varName} = "Variable variable";echo $testvarVar;I was trying to do it like this: $test{$varName}which didn't work.I didn't look at the user notes on the manual page before...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...