dwest Posted January 29, 2007 Share Posted January 29, 2007 [code]foreach($_POST['hid_price'.$id] as $price){$total = ($price*$qty);}[/code]Note the $id tacked on to "hid_price"...the result being hid_price1, 2, etc.How would I go about tacking the value of $id on to the $total variable name so I get a corresponding variable named $total1, $total2, etc.?Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/36120-concatenation-problemi-think/ Share on other sites More sharing options...
pocobueno1388 Posted January 29, 2007 Share Posted January 29, 2007 [code]$_POST['hid_price'.$id][/code]I'm pretty sure you can't do that. I'm not exactly sure what your trying to do...if you want to print out hid_price1 you would do:[code]echo $hid_price.$id;[/code]Why do you even want to include the ID in your foreach statement? All it deals with is the price and quantity. Maybe I am just not understanding... Quote Link to comment https://forums.phpfreaks.com/topic/36120-concatenation-problemi-think/#findComment-171521 Share on other sites More sharing options...
dwest Posted January 29, 2007 Author Share Posted January 29, 2007 Well, best not to worry with why as it is a long answer and not relevant to the question. ;)Let me attempt to make the question a bit more simple.I have a variable called $var.I want a new variable called $var1.The "1" in the variable name $var1, should be the value held in $id.So in effect I want to create a dynamic variable NAME to be used in the code. Not a dynamic variable.Make sense?Any way to do that?Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/36120-concatenation-problemi-think/#findComment-171529 Share on other sites More sharing options...
dwest Posted January 29, 2007 Author Share Posted January 29, 2007 Would $var{$id} create a variable with the name of $var plus whatever the value of $id is? Quote Link to comment https://forums.phpfreaks.com/topic/36120-concatenation-problemi-think/#findComment-171539 Share on other sites More sharing options...
spfoonnewb Posted January 29, 2007 Share Posted January 29, 2007 [code]$_POST["hid_price$id"][/code] Quote Link to comment https://forums.phpfreaks.com/topic/36120-concatenation-problemi-think/#findComment-171540 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.