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
https://forums.phpfreaks.com/topic/271904-adding-within-a-foreach/
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.

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

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.