Welcome Guest, Not a member yet? Register   Sign In
Remove duplicates from Multi-dimensional array
#1

[eluser]BiSHGoD[/eluser]
Hello.
I've been using CI for a few weeks now and I'm really liking it. I wonder if there is any function/library to clean up a multidimensional array based on a specific key.

On PHP.net I see a lot of fixes for this problem but none that I think apply to me.

I have a multidimensional array with a few keys that might be duplicate, which can be. I have one single key that I want to be unique though.

Code:
Array
(
    [0] => Array
        (
            [lid] => 4
            [timestamp] => 2009-08-10 14:46:34
            [number] => CI00101
            [location] => 358 A
        )

    [1] => Array
        (
            [lid] => 5
            [timestamp] => 2009-08-10 14:46:38
            [number] => CI00101
            [location] => 358 A
        )

    [2] => Array
        (
            [lid] => 9
            [timestamp] => 2009-08-10 15:54:30
            [number] => CI00101
            [location] => 358 B
        )
)

I want to remove dupliates based on the "location" key. So [2] should be removed, since it has the same value, 358 B, as [0].

You'll notice that "number" is the same on all of them, that shouldn't check for duplicates based on that key.

This data is from a mysql database..so if we can do this in the select statement that would work as well (right now it's 'select * from log where number = CI00101')

Thanks!


Messages In This Thread
Remove duplicates from Multi-dimensional array - by El Forum - 08-10-2009, 04:07 PM
Remove duplicates from Multi-dimensional array - by El Forum - 08-10-2009, 04:23 PM
Remove duplicates from Multi-dimensional array - by El Forum - 08-10-2009, 04:32 PM
Remove duplicates from Multi-dimensional array - by El Forum - 08-11-2009, 08:19 AM



Theme © iAndrew 2016 - Forum software by © MyBB