array_unique function for multi-dimensional arrays

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
visionmaster
Forum Contributor
Posts: 139
Joined: Wed Jul 14, 2004 4:06 am

array_unique function for multi-dimensional arrays

Post by visionmaster »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello together,

What is the best and performent solution for an array_unique function for following array structure? Something recursive or a further temporary array?

Code: Select all

$arrStackHeader[] = array("plural" => "machines" ,"singular" => "machine");
$arrStackHeader[] = array("plural" => "molding machines" ,"singular" => "machine");
...


Following condition should be fulfilled:

1. Relevant for determining unique rows is the column "singular".
2. Elements that are on top of the stack ([0]) have absolute priority.


Original array:

Code: Select all

Array
(
    [0] => Array
        (
            [plural] => machines
            [singular] => machine
        )

    [1] => Array
        (
            [plural] => molding machines
            [singular] => machine
        )

)
Result array should look like this:

Code: Select all

Array
(
    [0] => Array
        (
            [plural] => machines
            [singular] => machine
        )
)

Appreciate your help and your suggestions!


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply