Array refactoring reconstruct a new two-dimensional array based on the mid's total investment in mid

Source: Internet
Author: User

$arr = Array (' mid ' = ' 28838 ', ' invest_money ' = ' 1196000 ', ' rm_id ' = ' 157733 ',), =&G T;array (' mid ' = ' 28838 ', ' invest_money ' = ' 1180000 ', ' rm_id ' = ' 157733 ', '), ' (' Mid ' =&gt ; ' 28838 ', ' invest_money ' = ' 910000 ', ' rm_id ' = ' 157733 ', ' 2205 ', ' = ', ' mid ' = ' 20191 ', ' Invest_money ' =& Gt ' 350000 ',' rm_id ' = ' 157733 ',),2207 = = Array (' mid ' = ' 20191 ', ' invest_money ' = ' 550000 ',   ' rm_id '  =>  ' 157733 ',)  ); $arr  = array_values ($arr); $new  = array ()  foreach ($arr  as  $key + $val)  {    if ($key  == 0)  {        $ new[$val [' mid ']] =  $val [' Invest_money '];    } else {         if (array_key_exists ($val [' mid '],  $new))  {              $new [$val [' Mid ']] +=  $val [' Invest_money '];         } else {              $new [$val [' Mid ']] =  $val [' Invest_money '];         }    }}  $new 2 = array (); foreach ($arr  as  $key = > $val)  {    foreach ($new  as  $k = $v)  {         if ($arr [$kEy][' mid '] ==  $k)  {            $ new2[$k] [' mid '] =  $k;             $new 2[$ k][' Invest_money '] =  $v;             $ new2[$k] [' rm_id '] =  $val [' rm_id '];        }     }} array   28838 =>     array         ' mid '  =>  28838       ' Invest_ Money '  => 3286000       ' rm_id '  =>   ' 157733 '     20191 =>     array        ' mid '  => 20191       ' Invest_money '  => 900000        ' rm_id ' =>   ' 157733 '

Array refactoring reconstructs a new two-dimensional array based on the mid-stack of all the investments that belong to mid

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.