0

I have a array of kind

Array
(
[1] => Array
    (
        [id] => 1
        [username] => test1
        [case1] => abc
        [case2] => zxc
    )

[0] => Array
    (
        [id] => 1
        [username] => test1
        [case1] => fdg
        [case2] => tyy
    )

)

As you can see only id and username is same rest are different. Now i want to make it unique. That if only id is same in inner arrays then also only one value should come either of both.

Can any one tell me how to do this?

Any help will be highly appreciated.

4 Answers 4

1

Using the unique data as keys makes this easy:

$unique = array();
foreach ($array as $item) {
    $unique[$item['id']] = $item;
}
Sign up to request clarification or add additional context in comments.

Comments

1

create a new array in which to push the inner arrays if there is no duplicate

Comments

1

Use this for finding & removing specific unique in array array_unique

Comments

1

You should use 'id', as key for your top array (or 'username'?).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.