The calculation method of the difficulty of the problem of the array de-weight statistics

Source: Internet
Author: User
A method of calculating the difficulty of the array de-weight statistic problem



There is an array that needs to be re-reorganized in the format of the array online discussion
------to solve the idea----------------------


$arra = Array (
0 = Array (
' id ' = 0,
' Send_mobile ' = ' 13267310236 ',
' C_content ' and ' The weather is hot note heatstroke '
),
1 = Array (
' id ' = 1,
' Send_mobile ' = ' 13267310285 ',
' C_content ' and ' The weather is hot note heatstroke '
),
2 = Array (
' id ' = 2,
' Send_mobile ' = ' 13267310126 ',
' C_content ' and ' The weather is hot note heatstroke '
),
3 = Array (
' id ' = 3,
' Send_mobile ' = ' 13267310166 ',
' c_content ' = ' weather heatstroke '
)
);

$ARRB = Array ();

foreach ($arra as $v) {
$b = $v [' c_content '];

$ARRB [$b] [' send_mobile ']. = ', '. $v [' Send_mobile '];
$ARRB [$b] = Isset ($ARRB [$b])? $ARRB [$b]: $v;
}

$ARRB = Array_values ($ARRB);
Print_r ($ARRB);
?>



------to solve the idea----------------------
Look at you that is to use c_id to make a distinction, then directly with the CID to do key, $arr [$cid] = $val
------to solve the idea----------------------
Hint you Chinese can be used as an array key

foreach ($arra as $k = + $v) {$res [$v [c_content]] = $v;}
A word OK
------to solve the idea----------------------
Create a new array of B, traverse the original arrays A, if the c_content in the Traverse item does not appear in B as the key name, insert a b[c_content]; otherwise, add the Send_mobile to the loop, and then sort the entire re-key value of the B array.
  • 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.