Jump to content

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!


This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.