PHP multidimensional array problem, ask God to solve thank you

Source: Internet
Author: User
$arr = array(                     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 array is jxs the same as their FD,FB,TCP,FBDH added.
How to turn the above array into the following result
Results:
Gzyx 3 2 1 3
BJCJ 1 0 1 0

Reply content:

$arr = array(                     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 array is jxs the same as their FD,FB,TCP,FBDH added.
How to turn the above array into the following result
Results:
Gzyx 3 2 1 3
BJCJ 1 0 1 0

/* Initialize array of operations */$arr = array (' ID ' =>7363, ' fd ' =>1, ' fb ' =>1, ' TCP ' =>0, ' FBDH ' =>1, ' Jxs ' =&G t; ' 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 '), $res = Array ();/* I'm not going to tell you I don't have to recycle array_walk just to look tall. */array_walk (    $arr, function ($item, $key) use (& $res) {/* To determine if an array exists for initialization */$member = & $res [$item [' Jxs '];    if (!isset ($member)) {$member = array (' fd ' =>0, ' fb ' =>0, ' TCP ' =>0, ' FBDH ' =>0);    }/* Add statistical results to the array_walk*/$member [' fd '] + = $item [' fd '];    $member [' fb '] + = $item [' FB '];    $member [' tcp '] + = $item [' TCP ']; $member [' fbdh '] + = $item [' Fbdh '];}); * Print result */array_walk ($res, function ($item, $key) {echo ' $key {$item [' fd '}} {$item [' fb ']} {$item [' TCP ']} {$item [' Fbdh '}}
";});/ * *GZYX 3 2 1 3 *BJCJ 1 0 1 0 *

Because you gave a data, I do not know whether this is the main idea, but somehow got the format you want. But really want to vomit groove, you this question estimate not how many people can see what you want to do?

I try to play the code even look at it, just follow my request to add a set of data it? Is it possible to add a group of measurements, or does my code not solve your problem? It's a great insult not to say anything, eh!

Sure enough to force lattice too high is not good, or silently change into a cycle bar t_t.

/* Initialize array of operations */$arr = array (' ID ' =>7363, ' fd ' =>1, ' fb ' =>1, ' TCP ' =>0, ' FBDH ' =>1, ' j xs ' = ' 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 '), $res = Array ();/* Actually I'm not going to tell you I don't need to recycle array_walk just to look tall. foreach ($arr as $item) {/* Determines if an array exists for initialization */$member = & $res [$item [' Jxs ']; if (!isset ($member)) {$member = array (' fd ' =>0, ' fb ' =>0, ' TCP ' =>0, ' FBDH ' =>0); }/* Add statistical results to the array_walk*/$member [' fd '] + = $item [' fd ']; $member [' fb '] + = $item [' FB ']; $member [' tcp '] + = $item [' TCP ']; $member [' fbdh '] + = $item [' Fbdh '];} /* Print result */foreach ($res as $key + $item) {echo ' $key {$item [' fd '}} {$item [' fb ']} {$item [' TCP ']} {$item [' FBDH ']} 
"; }/* *GZYX 3 2 1 3 *BJCJ 1 0 1 0 */
  • 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.