Welcome Guest, Not a member yet? Register   Sign In
array array_sum get error message
#1

Results from the table:
Code:
Array (
   [0] => stdClass Object (
       [ID] => 00058
       [income_campaign] => 00001
       [income_country] =>
       [income_value] => 0.00
       [income_date] => 2019-02-11
       )
   [1] => stdClass Object (
       [ID] => 00056
       [income_campaign] => 00001
       [income_country] => 1US, 3PH, 2CN, 9TH
       [income_value] => 12.00
       [income_date] => 2019-02-12
   )
   [2] => stdClass Object (
       [ID] => 00059
       [income_campaign] => 00001
       [income_country] => 1US
       [income_value] => 12.00
       [income_date] => 2019-02-10
   )
   [3] => stdClass Object (
       [ID] => 00061
       [income_campaign] => 00001
       [income_country] => 2US
       [income_value] => 12.00
       [income_date] => 2019-02-09
   )
)

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();

foreach (
$data['data_user_income'] as $a => $b) {

   foreach (
$b as $c => $d) {
      
$sum[$c]+=$d;
   }
}
print_r($sum);

// Error message :
// Message: Undefined index: ID,income_value .... etc. 
Reply


Messages In This Thread
array array_sum get error message - by DELE - 02-16-2019, 12:01 PM
RE: array array_sum get error message - by DELE - 02-16-2019, 07:54 PM
RE: array array_sum get error message - by DELE - 02-17-2019, 04:25 AM



Theme © iAndrew 2016 - Forum software by © MyBB