array array_sum get error message - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: array array_sum get error message (/showthread.php?tid=72833) |
array array_sum get error message - DELE - 02-16-2019 Results from the table: Code: Array ( I want to sum an income_value value, so the results obtained are 36.00 I have tried this code but always get an error message: PHP Code: $sum = array(); RE: array array_sum get error message - jreklund - 02-16-2019 Those aren't arrays, but objects inside an array. So that would be: PHP Code: $sum = 0; RE: array array_sum get error message - DELE - 02-16-2019 thank you very much for your help, but why are the results not decimal if using this method? RE: array array_sum get error message - jreklund - 02-17-2019 As there are no decimals to be added, it removes it. If you wan't to display them with decimals, you need to use number_format. http://php.net/manual/en/function.number-format.php PHP Code: echo number_format($sum, 2); RE: array array_sum get error message - DELE - 02-17-2019 But is there really no other way to add these decimal values? because I save a decimal value in the database. I agree with what you explained above, but I prefer simpler code if there is one. RE: array array_sum get error message - jreklund - 02-17-2019 Not to my knowledge. |