Jump to content

Adding Within A Foreach


dreampho

Recommended Posts

Hi. I am using a CMS that outputs rows of data between tag pairs.

 

I am guessing this is basically a foreach statement. It runs through the rows until there are no more, outputting the data.

 

So for example:

 

{order_items}
{price}
{/order_items

 

If I had two rows, and the price data was 200 and 300, it would output 200300

 

Is there anyway to add these two numbers together?

 

Thank you :)

Link to comment
Share on other sites

Hi. I am using a CMS that outputs rows of data between tag pairs.

 

I am guessing this is basically a foreach statement. It runs through the rows until there are no more, outputting the data.

 

So for example:

 

{order_items}
{price}
{/order_items

 

If I had two rows, and the price data was 200 and 300, it would output 200300

 

Is there anyway to add these two numbers together?

 

Thank you :)

 

Do you mean add them together mathematically?  Or add them together as you've done above: 200300...

 

Provide a pseudo example of a desired output, exactly as you imagine it to be.

Link to comment
Share on other sites

Hi. Thank you for your reply.

 

Sorry, I need them to be mathmatically added together.

 

So, if the example still stands, I would want the 200 + 300 = 500, being able to echo out 500.

 

I tried adding them into an array, but because of the loop, it just created an array per loop...

Link to comment
Share on other sites

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.