Array calculation of difference and subtotal of items

Source: Internet
Author: User
$s = Array (0 = = Array (0 = = Array (0 = ' 2014-04-11 ', ' time ' = ' 2014-04-11 ', 1 = ' bea01-120n ', ' type ') = ' bea01-120n ', 2 = 176, ' count ' = 176, 1 = = Array (0 = ' 2014-04-11 ', ' time ' = ' 2014-04-11 ', 1 = ' bea21-110n ', ' type ' = ' bea21-110n ', 2 = 1056, ' count ' = 1056, '), 1 = = Array (0 = = Array (0 = ' 2014-04-11 ', ' time ' = ' 2014-04-11 ', 1 = ' bea01-120n ', ' type ' = ' bea01-120n ', 2 = 192, ' count ' = 192,), 1 = = Array (0 = ' 2014-04-11 ', ' time ' = ' 2014-04-11 ', 1 = ' bea21-110n ', ' type ' = ' bea21-110n ', 2 = 960, ' count ' = 960,),),

A subtotal of the type entry for which the type corresponds to the difference and $s[0] and $s[1]. (Subtotal has been implemented, with unset)


The ideal result:

Subtotal results: bea01-120n 176 bea01-120n 192 Difference Value: 176-192 = 16
bea21-110n 1056 bea21-110n 960 1056-960 = 96
Subtotal: 176+1056=1232 192+960 = 1152


Reply to discussion (solution)

$s = Array (0 = = Array (0 = = Array (0 = ' 2014-04-11 ', ' time ' = ' 2014-04-11 ', 1 = ' BEA01 -120n ', ' type ' = ' bea01-120n ', 2 = 176, ' count ' = 176, 1 = = Array (0 = ' 2014-04-11 ')    , ' time ' = ' 2014-04-11 ', 1 = ' bea21-110n ', ' type ' = ' bea21-110n ', 2 = 1056, ' count ' = 1056, ), 1 = = Array (0 = = Array (0 = ' 2014-04-11 ', ' time ' = ' 2014-04-11 ', 1 = ' bea01-12 0N ', ' type ' = ' bea01-120n ', 2 = 192, ' count ' = 192, 1 = = Array (0 = ' 2014-04-11 ', '   Time ' = ' 2014-04-11 ', 1 = ' bea21-110n ', ' type ' = ' bea21-110n ', 2 = 960, ' count ' = 960, ), function foo ($a, $b) {for ($i =0; $i
   
  
Array (    [0] = = Array        (            [0] = = bea01-120n            [1] = -16        )    [1] = = Array        (            [0] = > bea21-110n            [1] = +)        )
Subtotal, you've done it, and I'm slacking off.

$s = Array (
0 = Array (
0 = Array (
0 = ' 2014-04-11 ', ' time ' = ' 2014-04-11 ',
1 = ' bea01-120n ', ' type ' = ' bea01-120n ',
2 = 176, ' count ' = 176,
),
1 = Array (
0 = ' 2014-04-11 ', ' time ' = ' 2014-04-11 ',
1 = ' bea21-110n ', ' type ' = ' bea21-110n ',
2 = 1056, ' count ' = 1056,
),
),
1 = Array (
0 = Array (
0 = ' 2014-04-11 ', ' time ' = ' 2014-04-11 ',
1 = ' bea01-120n ', ' type ' = ' bea01-120n ',
2 = 192, ' count ' = 192,
),
1 = Array (
0 = ' 2014-04-11 ', ' time ' = ' 2014-04-11 ',
1 = ' bea21-110n ', ' type ' = ' bea21-110n ',
2 = 960, ' count ' = 960,
),
),
);
function my ($a, $b) {
foreach ($a as $k = = $v) {
echo $a [$k] [' count ']-$b [$k] [' count ']. "
";
}
}
Call_user_func_array (' my ', $s);

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.