dreampho Posted December 12, 2012 Share Posted December 12, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/271904-adding-within-a-foreach/ Share on other sites More sharing options...
Muddy_Funster Posted December 12, 2012 Share Posted December 12, 2012 there is always a way. Youre welcome Quote Link to comment https://forums.phpfreaks.com/topic/271904-adding-within-a-foreach/#findComment-1398899 Share on other sites More sharing options...
dreampho Posted December 12, 2012 Author Share Posted December 12, 2012 Okay, well thats good to know. I guess my next question would be, how? Quote Link to comment https://forums.phpfreaks.com/topic/271904-adding-within-a-foreach/#findComment-1398904 Share on other sites More sharing options...
Muddy_Funster Posted December 12, 2012 Share Posted December 12, 2012 that depends on the code, without knowing what's going on how can we suggest how to change it? Quote Link to comment https://forums.phpfreaks.com/topic/271904-adding-within-a-foreach/#findComment-1398905 Share on other sites More sharing options...
dreampho Posted December 12, 2012 Author Share Posted December 12, 2012 What I am wondering is if there is a way to place that tag pair within some PHP so I can output the rows in different variables to add together. Quote Link to comment https://forums.phpfreaks.com/topic/271904-adding-within-a-foreach/#findComment-1398907 Share on other sites More sharing options...
mrMarcus Posted December 12, 2012 Share Posted December 12, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/271904-adding-within-a-foreach/#findComment-1398916 Share on other sites More sharing options...
dreampho Posted December 13, 2012 Author Share Posted December 13, 2012 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... Quote Link to comment https://forums.phpfreaks.com/topic/271904-adding-within-a-foreach/#findComment-1399100 Share on other sites More sharing options...
Muddy_Funster Posted December 13, 2012 Share Posted December 13, 2012 here's a hint for you if(!isset($code) or $code == '' or empty($code)){ $answers = false; } else{ $answers = true; } If you want answers you need to provide the code. Quote Link to comment https://forums.phpfreaks.com/topic/271904-adding-within-a-foreach/#findComment-1399106 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.