-2
    Array
    (
        [piata-fortei-munca] => Array
            (
                [0] => Array
                    (
                        [date] => 2019-10-19 09:10:07
                        [user] => 61006cd2ac1728c3c08c2e8d9d714a81
                        [slug] => piata-fortei-munca
                    )

                [1] => Array
                    (
                        [date] => 2019-10-19 09:10:07
                        [user] => 61006cd2ac1728c3c08c2e8d9d714a81
                        [slug] => piata-fortei-munca
                    )

                [2] => Array
                    (
                        [date] => 2019-10-19 09:10:09
                        [user] => a8b6c2879aa0f38da1fd49a4e86e1525
                        [slug] => piata-fortei-munca
                    )

                [3] => Array
                    (
                        [date] => 2019-10-19 09:10:09
                        [user] => a8b6c2879aa0f38da1fd49a4e86e1525
                        [slug] => piata-fortei-munca
                    )

                [4] => Array
                    (
                        [date] => 2019-10-19 09:10:18
                        [user] => 42d80d8dc9a9547223e2bfea172738cf
                        [slug] => piata-fortei-munca
                    )
[blockchain-bitcoin] => Array
        (
            [0] => Array
                (
                    [date] => 2019-10-19 08:10:58
                    [user] => 4b01473f1d3f1846b1e83b33e1af0b11
                    [slug] => blockchain-bitcoin
                )

            [1] => Array
                (
                    [date] => 2019-10-19 08:10:58
                    [user] => 4b01473f1d3f1846b1e83b33e1af0b11
                    [slug] => blockchain-bitcoin
                )

        )
)

i have an array structure like this i want to remove duplicates

for example, for key [piata-fortei-munca] multiple arrays have same user and slug [user] => 61006cd2ac1728c3c08c2e8d9d714a81 [slug] => piata-fortei-munca

if same user and slug exist then remove the multiple entries from array if anybody knows the logic ,please help me

ANGELA
  • 27
  • 5
  • 3
    Possible duplicate of [How to remove duplicate values from a multi-dimensional array in PHP](https://stackoverflow.com/questions/307674/how-to-remove-duplicate-values-from-a-multi-dimensional-array-in-php) – LetsSeo Oct 19 '19 at 18:36
  • @LetsSeo not getting – ANGELA Oct 19 '19 at 18:51
  • I find dissonance between the question requirements and the accepted answer. If the accepted answer is correct, then the question is wrong and this page can be closed with https://stackoverflow.com/q/45603614/2943403. If the question requirements are correct, then Nigel's answer is correct and there is surely another duplicate that can be used to close this page with. The asker seems to ask for uniqueness based on two columns, but the [mcve] is low-quality because the `date` values do not differ -- this means that whole rows can be used to determine uniqueness (by happenstance). – mickmackusa May 19 '22 at 06:36

2 Answers2

1

You could use array_walk with array_column and array_values

array_walk($a, function(&$v ,$k){
    $v  = array_values(array_column($v, null, 'user'));
});
print_r($a);

Working example :- https://3v4l.org/k3d4T

Rakesh Jakhar
  • 6,380
  • 2
  • 11
  • 20
0

As it is 2 of the 3 values you want to get as the unique identity, you can combine these two values to create a composite key for a temporary array. Then once you have created this intermediate array, use array_values() to remove the composite key...

$output = [];
foreach ( $data['piata-fortei-munca'] as $entry )   {
    $output[$entry['user']."#".$entry['slug']] = $entry;
}

print_r(array_values($output));

with your test data gives...

Array
(
    [0] => Array
        (
            [date] => 2019-10-19 09:10:07
            [user] => 61006cd2ac1728c3c08c2e8d9d714a81
            [slug] => piata-fortei-munca
        )

    [1] => Array
        (
            [date] => 2019-10-19 09:10:09
            [user] => a8b6c2879aa0f38da1fd49a4e86e1525
            [slug] => piata-fortei-munca
        )

    [2] => Array
        (
            [date] => 2019-10-19 09:10:18
            [user] => 42d80d8dc9a9547223e2bfea172738cf
            [slug] => piata-fortei-munca
        )

)
Nigel Ren
  • 56,122
  • 11
  • 43
  • 55