Php multi-dimensional array

Source: Internet
Author: User
My multi-dimensional array code is as follows: $ arrarray (array (id & gt; 7363, fd & gt; 1, fb & gt; 1, tcp & gt; 0, fbdh & gt; 1, jxs & gt; GZYX), array (id & gt; 7412, fd & gt; 1, fb & gt; my multi-dimensional array code is as follows:

$ Arr = array ('id' => 7363, 'fd '=> 1, 'FB' => 1, 'tcp '=> 0, 'fbdh '=> 1, 'jxs' => 'gzyx'), array ('id' => 7412, 'fd '=> 1, 'FB' => 0, 'tcp '=> 1, 'fbdh' => 1, 'jxs '=> 'gzyx'), array ('id' => 7512, 'fd' => 1, 'FB '=> 1, 'tcp' => 0, 'fbdh '=> 1, 'jxs' => 'gzyx'), array ('id' => 7516, 'fd '=> 1, 'FB' => 0, 'tcp '=> 1, 'fbdh' => 0, 'jxs '=> 'bjcj '),); // It means that the jxs in the array are the same as their fd, fb, tcp, and fbdh. // How can I convert the above array into the following result? // result: GZYX 3 2 1 3 BJCJ 1 0 1 0

---------- Solution ------------

 7363,'fd'=>1,'fb'=>1,'tcp'=>0,'fbdh'=>1,'jxs'=>'GZYX'),     array('id'=>7412,'fd'=>1,'fb'=>0,'tcp'=>1,'fbdh'=>1,'jxs'=>'GZYX'),     array('id'=>7512,'fd'=>1,'fb'=>1,'tcp'=>0,'fbdh'=>1,'jxs'=>'GZYX'),     array('id'=>7516,'fd'=>1,'fb'=>0,'tcp'=>1,'fbdh'=>0,'jxs'=>'BJCJ'), );   $result = []; foreach ($arr as $a)  {     if (empty($result[$a['jxs']])) {         $result[$a['jxs']] = $a;     } else {         foreach ($a as $k => $v) {             $result[$a['jxs']][$k] += $v;         }     } }   foreach ($result as $k => $r) {     echo sprintf("%s %d %d %d %d\n",                  $k, $r['fd'], $r['fb'], $r['tcp'], $r['fbdh']); }

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.