How to remove duplicate entries from multidimensional array?

Dev Troubleshooter

In the below array linked_article_id has value 3 two times but I want to remove one entry from this array (i.e I want only one unique linked_article_id value). I tried the below function but did't work for me:

$input = array_map("unserialize", array_unique(array_map("serialize", $input)));

Array:

Array ( [0] => Array ( [id] => 193 [linked_article_id] => 2 [article_id] => 1 [article_title] => Test header link [slug] => test-header-link )
        [1] => Array ( [id] => 195 [linked_article_id] => 3 [article_id] => 1 [article_title] => upload image test [slug] => upload-image-test ) 
        [2] => Array ( [id] => 197 [linked_article_id] => 4 [article_id] => 1 [article_title] => Adrenal Fatigue [slug] => arrowdesigns01-test ) 
        [3] => Array ( [id] => 200 [linked_article_id] => 9 [article_id] => 1 [article_title] => Recipe2 [slug] => recipe2 )
        [4] => Array ( [id] => 211 [linked_article_id] => 15 [article_id] => 1 [article_title] => New [slug] => new )
        [5] => Array ( [id] => 214 [linked_article_id] => 3 [article_id] => 1 [article_title] => upload image test [slug] => upload-image-test ) 
)
AbraCadaver

Serialization is used to compare if the entire arrays are indentical, not just one key.

You can extract the array and index (which must be unique) by linked_article_id:

$input = array_column($input, null, 'linked_article_id');

If you really need to re-index after (optional):

$input = array_values(array_column($input, null, 'linked_article_id'));

I don't see how anyone could be running PHP < 5.5.0 now, but just in case:

foreach($input as $v) {
    $result[$v['linked_article_id']] = $v;
}

Then if needed:

$result = array_values($result);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Remove unnecessary value entries from multidimensional array in c?

From Dev

how to remove an array from a multidimensional array?

From Dev

How to remove duplicate key value array in multidimensional array

From Dev

How to remove duplicate values from a multidimensional array?

From Dev

How to remove specific indices from a filtered list that has duplicate entries?

From Dev

Remove an element from array and save other duplicate entries

From Dev

JavaScript: How to remove the duplicate entries from array with respect to multiple keys

From Dev

Remove duplicate entries from string array column of postgres

From Dev

How to remove duplicate entries from a list of list

From Dev

How to remove duplicate entries in dash?

From Dev

Remove duplicate values from a multidimensional array in PHP

From Dev

How to remove duplicate entries from associative array in php

From Dev

Remove duplicate entries from array of arrays (javascript)

From Dev

How to remove duplicate entries from a list in python

From Dev

remove duplicate values from multidimensional array by single value

From Dev

How to remove duplicate entries in iTunes

From Dev

PHP- Remove duplicate value from multidimensional array

From Dev

remove duplicate values from multidimensional array

From Dev

Disregard both duplicate entries from multidimensional array

From Dev

How to remove duplicate entries

From Dev

I have multidimensional array in php and want to remove duplicate entries on the basis of 3 column

From Dev

How to remove duplicate entries in array but keep their values by overwriting

From Dev

How to remove duplicate entries from FragmentManager?

From Dev

Remove duplicate values from a multidimensional array

From Dev

Remove item with duplicate ID from multidimensional array with criterion which to keep

From Dev

Remove duplicate combination of elements from multidimensional array

From Dev

How to remove duplicate entries from a json file?

From Dev

How to remove duplicate entries from array of arrays based on nested value?

From Dev

Remove duplicate from multidimensional array but keep lowest value

Related Related

  1. 1

    Remove unnecessary value entries from multidimensional array in c?

  2. 2

    how to remove an array from a multidimensional array?

  3. 3

    How to remove duplicate key value array in multidimensional array

  4. 4

    How to remove duplicate values from a multidimensional array?

  5. 5

    How to remove specific indices from a filtered list that has duplicate entries?

  6. 6

    Remove an element from array and save other duplicate entries

  7. 7

    JavaScript: How to remove the duplicate entries from array with respect to multiple keys

  8. 8

    Remove duplicate entries from string array column of postgres

  9. 9

    How to remove duplicate entries from a list of list

  10. 10

    How to remove duplicate entries in dash?

  11. 11

    Remove duplicate values from a multidimensional array in PHP

  12. 12

    How to remove duplicate entries from associative array in php

  13. 13

    Remove duplicate entries from array of arrays (javascript)

  14. 14

    How to remove duplicate entries from a list in python

  15. 15

    remove duplicate values from multidimensional array by single value

  16. 16

    How to remove duplicate entries in iTunes

  17. 17

    PHP- Remove duplicate value from multidimensional array

  18. 18

    remove duplicate values from multidimensional array

  19. 19

    Disregard both duplicate entries from multidimensional array

  20. 20

    How to remove duplicate entries

  21. 21

    I have multidimensional array in php and want to remove duplicate entries on the basis of 3 column

  22. 22

    How to remove duplicate entries in array but keep their values by overwriting

  23. 23

    How to remove duplicate entries from FragmentManager?

  24. 24

    Remove duplicate values from a multidimensional array

  25. 25

    Remove item with duplicate ID from multidimensional array with criterion which to keep

  26. 26

    Remove duplicate combination of elements from multidimensional array

  27. 27

    How to remove duplicate entries from a json file?

  28. 28

    How to remove duplicate entries from array of arrays based on nested value?

  29. 29

    Remove duplicate from multidimensional array but keep lowest value

HotTag

Archive