cinek Posted January 28, 2011 Share Posted January 28, 2011 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 More sharing options...
ShadowMage Posted January 28, 2011 Share Posted January 28, 2011 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 More sharing options...
cinek Posted January 28, 2011 Author Share Posted January 28, 2011 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 More sharing options...
ShadowMage Posted January 28, 2011 Share Posted January 28, 2011 Yeah, what you're looking for are variable variables. But I can't seem to get the syntax right....I know I've used them before... Link to comment Share on other sites More sharing options...
cinek Posted January 28, 2011 Author Share Posted January 28, 2011 Yeah, what you're looking for are variable variables. But I can't seem to get the syntax right....I know I've used them before... thanks a lot got it working Link to comment Share on other sites More sharing options...
ShadowMage Posted January 28, 2011 Share Posted January 28, 2011 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.