There is a two-dimensional array. I want to retrieve a set of keys and calculate the sum. this is a two-dimensional array. I want to go to the total set and calculate the total value, how can I implement array (& nbsp; [0] & nbsp; & gt; & nbsp; Array & nbsp; (& nbsp; [id] & nbsp; & there is a two-dimensional Array. I want to retrieve a set of keys and calculate the sum.
This is a two-dimensional array. I want to go to the total set and calculate the total value. how can I implement this?
Array (
[0] => Array (
[Id] => 5
[Title] => Sept. grass 8 times gel cream 50g moisturizing whitening cream lotion genuine skin care products for men and women
[Images] => uploadfile/goods/2015-01/1420774763. jpg
[Price] = & gt; 39.0
[Num] => 1
[Total] => 39
[Wlmoney] => 0
[Url] => http: // localhost/dkyq/goods. php? Id = 12)
[1] => Array (
[Id] => 4
[Title] => skin lotion, genuine water source cleanser, facial cleanser, 75 ml cleanser, cleansing, refreshing, moisturizing
[Images] => uploadfile/goods/2015-01/1420773795. jpg
[Price] = & gt; 12.0
[Num] => 1
[Total] => 12
[Wlmoney] => 0
[Url] => http: // localhost/dkyq/goods. php? Id = 11
)
);
------ Solution ----------------------
$ Ar = array (
0 => array (
'Id' => '5 ',
'Title' => '50g moisturizing whitening cream lotion male and female genuine skin care s ',
'Images' => 'uploadfile/goods/2015-01/1420774763. jpg ',
'Price' => '39. 0 ',
'Num' => '1 ',
'Total' => '39 ',
'Wlmoney' => '0 ',
'URL' => 'http: // localhost/dkyq/goods. php? Id = 12 ',
),
1 => array (
'Id' => '4 ',
'Title' => 'Skin lotion genuine water source cleanser 75 ml cleanser cleansing and moisturizing ',
'Images' => 'uploadfile/goods/2015-01/1420773795. jpg ',
'Price' => '12. 0 ',
'Num' => '1 ',
'Total' => '12 ',
'Wlmoney' => '0 ',
'URL' => 'http: // localhost/dkyq/goods. php? Id = 11 ',
),
);
$ Total = 0;
Foreach ($ ar as $ r) $ total + = $ r ['total'];
Echo $ total; // 51
------ Solution ----------------------
$ Arr = array (
Array (
'Id' => '5 ',
'Title' => '50g moisturizing whitening cream lotion male and female genuine skin care s ',
'Images' => 'uploadfile/goods/2015-01/1420774763. jpg ',
'Price' => '39. 0 ',
'Num' => '1 ',
'Total' => '39 ',
'Wlmoney' => '0 ',
'URL' => 'http: // localhost/dkyq/goods. php? Id = 12 ',
),
Array (
'Id' => '4 ',
'Title' => 'Skin lotion genuine water source cleanser 75 ml cleanser cleansing and moisturizing ',
'Images' => 'uploadfile/goods/2015-01/1420773795. jpg ',
'Price' => '12. 0 ',
'Num' => '1 ',
'Total' => '12 ',
'Wlmoney' => '0 ',
'URL' => 'http: // localhost/dkyq/goods. php? Id = 11 ',
)
);
$ Total = 0;
Foreach ($ arr as $ v ){
$ Total + = $ v ['total'];
}
Echo $ total;
Total = 51