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. 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. 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. Link to comment Share on other sites More sharing options...
FreakusBzzz Posted January 13, 2019 Author Share Posted January 13, 2019 see next 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. Link to comment Share on other sites More sharing options...
ginerjm Posted January 13, 2019 Share Posted January 13, 2019 $itemAnnua ? [ i ] ?? 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]; } Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.