Jump to content

concatenation problem...I think


dwest

Recommended Posts

[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!
Link to comment
https://forums.phpfreaks.com/topic/36120-concatenation-problemi-think/
Share on other sites

[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...
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!


Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.