Zimo
Zimo

Reputation: 1

How can remove duplicate value in PHP

I have a some data stored in $data[], there are some items in it. How do I remove duplicate values in a foreach?

Array
(
    [0] => ABC
)
Array
(
    [0] => XZY
)
Array
(
    [0] => ABC
)

i have use some function array unique and convert it to json ... and not work

Upvotes: 0

Views: 62

Answers (3)

Rp9
Rp9

Reputation: 1963

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

Upvotes: 0

Darshan Jain
Darshan Jain

Reputation: 499

Use array_unique($array) function in order to remove duplicate value. It takes an input array and returns a new array without duplicate values.

Upvotes: 2

Karlo Kokkak
Karlo Kokkak

Reputation: 3714

You can use array_merge() first. Then on result do array_unique();

Upvotes: 0

Related Questions