PHP multidimensional array de-weight

Source: Internet
Author: User
PHP multi-dimensional array de-weight, how to remove the name of the extra one?
Array
(
[0] = = Array
(
[id] = 79
[Name] = a
)

[1] = = Array
(

[id] = 79
[Name] = a
)
[2] = = Array
(
[id] = 78
[Name] = b
)
[3] = = Array
(

[id] = 36
[Name] = C
)
)


Reply to discussion (solution)

$ar = Array (0 = = Array (' id ' = ' + ',    ' name ' = = ' A ',  ), 1 = =   Array (    ' id ' = > ' + ',    ' name ' = ' a ', ', '  2 = =   Array (    ' id ' = ' + ',    ' name ' = ' B ',  ), C15/>3 = =   Array (    ' id ' = ' + ',    ' name ' = = ' C ',  ),), foreach ($ar as $k = = $f) {  foreach ($ar as $p + $t) if ($k! = $p && $f = = $t) unset ($ar [$k]);} Print_r ($ar);
Array (    [1] = = Array        (            [id] = +            [name] + a        )    [2] = = Array        (            [id] = [            name] + b        )    [3] = = Array        (            [id] = [            name] = + C        ))

$arr =array (     0=>array (        ' id ' =>79,        ' name ' = ' A '         ),     1=>array (        ' id ' =>79,        ' Name ' = ' A '      ),     2=>array (        ' id ' =>78,        ' name ' = ' B '     ),     3=>array (        ' Id ' =>36,        ' name ' = ' C '     ), $item =array (); foreach ($arr as $k + = $v) {    if (!isset ($item [$v [' ID '] ]) $item [$v [' id ']]= $v;} Print_r (Array_values ($item));

Array (    [0] = = Array        (            [id] = +            [name] + a        )    [1] = = Array        (            [id] = [            name] + b        )    [2] = = Array        (            [id] = [            name] = + C        ))

 
     Array (    ' id ' = ' + ',    ' name ' = ' a ',  ),  1 = =   Array (    ' id ' = ' + ',    ' name ' = ' = ') A ',  ),  2 = =   Array (    ' id ' = ' + ',    ' name ' = ' B ',  ),  3 = =   Array ( c18/> ' id ' = ' + ',    ' name ' = ' C ', '  ), $temp =array (); $result =array (); foreach ($ar as $item) {$temp [] = Json_encode ($item);} $temp = Array_unique ($temp), foreach ($temp as $item) {$result [] = Json_decode ($item, True);} Var_dump ($result);

Just providing new ideas is inefficient.


Array (3) {  [0]=>  Array (2) {    ["id"]=>    string (2) "" "    [" Name "]=>    string (1)" A "  }  [1]=>  Array (2) {    [" id "]=>    string (2)" "    [" Name "]=>    string (1)" B "  }  [2]=>  Array (2) {    ["id"]=>    string (2) "1"    ["Name"]=>    string () "C"  }}

$ar = Array (0 = = Array (' id ' = ' + ',    ' name ' = = ' A ',  ), 1 = =   Array (    ' id ' = > ' + ',    ' name ' = ' a ', ', '  2 = =   Array (    ' id ' = ' + ',    ' name ' = ' B ',  ), C15/>3 = =   Array (    ' id ' = ' + ',    ' name ' = = ' C ',  ),), foreach ($ar as $k = = $f) {  foreach ($ar as $p + $t) if ($k! = $p && $f = = $t) unset ($ar [$k]);} Print_r ($ar);
Array (    [1] = = Array        (            [id] = +            [name] + a        )    [2] = = Array        (            [id] = [            name] + b        )    [3] = = Array        (            [id] = [            name] = + C        ))


If it's just the ID repetition, how do I remove the name?

Then you have #2 code.
But strictly speaking, it's not "going heavy" but "clustering."
Just one for the same set of data, a little bit of a database of group flavor

Then you have #2 code.
But strictly speaking, it's not "going heavy" but "clustering."
Just one for the same set of data, a little bit of a database of group flavor


Can you directly filter out the duplicates when you query?

SELECT DISTINCT (' id ') as ' id ', name from ' TABLE '

SELECT DISTINCT (' id ') as ' id ', name from ' TABLE '


This is my SQL, how can I change the wrong, please help me change it, thank you
$sql = "Select T3.width as width, t3.height as height,t1.add_time as add_time,t1.add_author as add_author,t1.image_url as Image_url,t1.id as id,t1.browse_real_cnt as browse_real_cnt from comments as T2 left joins ornamentations as T1 on t1.id = T2.object_id left joins Ornamentation_images as T3 on t3.ornamentation_id = t1.id where (T2.uid = $id) and (t1.enable = ' 0 ') ORDER by id desc LIMIT 0,5 ";

Which field do you repeat?

  • 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.