FreakusBzzz Posted January 13, 2019 Share Posted January 13, 2019 How do I re write my code so it's $itemAnnual0 = $values[0] * $periods[0]; $itemAnnual1 = $values[1] * $periods[1]; $itemAnnual2 = $values[2] * $periods[2]; ... $itemAnnual79 = $values[79] * $periods[79]; And for my previous post, I solved it. Quote Link to comment Share on other sites More sharing options...
ajoo Posted January 13, 2019 Share Posted January 13, 2019 A simple for loop would do the trick. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted January 13, 2019 Share Posted January 13, 2019 Quote How to short hand this $values and $periods are already arrays. do the same for $ItemsAnnual and make it an array and populate its values using a loop. Quote Link to comment Share on other sites More sharing options...
FreakusBzzz Posted January 13, 2019 Author Share Posted January 13, 2019 (edited) see next Edited January 13, 2019 by FreakusBzzz incorrect Quote Link to comment Share on other sites More sharing options...
FreakusBzzz Posted January 13, 2019 Author Share Posted January 13, 2019 Sorry, I meant: or ($i = 0; $i <= 6; $i++) { $incomeSubtotal += $values[$i] * $periods[$i]; $itemAnnual[i] = $values[$i] * $periods[$i]; } it no longer works, so $itemAnnua[i]l doesnt work when i=2 but $itemAnnual2 does. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted January 13, 2019 Share Posted January 13, 2019 $itemAnnua ? [ i ] ?? Quote Link to comment Share on other sites More sharing options...
Barand Posted January 13, 2019 Share Posted January 13, 2019 try $itemAnnual = []; foreach ($values as $k => $value) { $itemAnnual[$k] = $value * $periods[$k]; } if you only want a single $itemAnnual total then try $itemAnnual = 0; foreach ($values as $k => $value) { $itemAnnual += $value * $periods[$k]; } Quote Link to comment 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.