PHP Array Unique Sort Regular not working as expected

PHP Array Unique Sort Regular not working as expected

I'm using print_r(array_unique($array, SORT_REGULAR)); on the array below but it does not work.

I'm using print_r(array_unique($array, SORT_REGULAR)); on the array below but it does not work.

I'm trying to filter out the redundant data.

Notice that [Order] and its key value pairs are all the same. But [Transaction] and its key value pairs are unique.

I need to get the [Order] element data and combine it with the 3 different [Transaction] elements.

My array

Array
(
    [0] => Array
        (
            [Order] => Array
                (
                    [PO] => TR11214
                    [OrderID] => 242856952012
                )

        [Transaction] => Array
            (
                [TransPO] => TR11211
                [TransactionPrice] => 91.17
            )

    )

[1] => Array
    (
        [Order] => Array
            (
                [PO] => TR11214
                [OrderID] => 242856952012
            )

        [Transaction] => Array
            (
                [TransPO] => TR11212
                [TransactionPrice] => 180.41
            )

    )

[2] => Array
    (
        [Order] => Array
            (
                [PO] => TR11214
                [OrderID] => 242856952012
            )

        [Transaction] => Array
            (
                [TransPO] => TR11213
                [TransactionPrice] => 209.99
            )

    )

)

The final array I need will look something like this.

Array
(
    [Order] => Array
        (
            [PO] => TR11214
            [OrderID] => 242856952012
        )

[Transaction] => Array
    (
        [0] => Array
            (
                [TransPO] => TR11211
                [TransactionPrice] => 91.17
            )

        [1] => Array
            (
                [TransPO] => TR11212
                [TransactionPrice] => 180.41
            )

        [2] => Array
            (
                [TransPO] => TR11213
                [TransactionPrice] => 209.99
            )

    )

)

I can flatten the original array and then use array_unique, but wanted to see if there is a better way to accomplish what I need.

my code:

$myarray = array(
    0 => array(
    "Order" => array("PO" => "TR11214", "OrderID" => 242856952012),
    "Transaction" => array("TransPO" => "TR11211", "TransactionPrice" => 91.17)
    ),
    1 => array(
    "Order" => array("PO" => "TR11214", "OrderID" => 242856952012),
    "Transaction" => array("TransPO" => "TR11212", "TransactionPrice" => 180.41)
    ),
    2 => array(
    "Order" => array("PO" => "TR11214", "OrderID" => 242856952012),
    "Transaction" => array("TransPO" => "TR11213", "TransactionPrice" => 209.99)
    )
);

print_r(array_unique($myarray, SORT_REGULAR));


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

PHP Interview Questions with Solutions: Prepare for PHP Interview

Prepare for PHP Interviews. Set Variable With php.ini File. Logic & Output Behind PHP Code Segment. Class Concept, Error & Functions in PHP. Start PHP Now!

PHP Web Application Development Company

As a top **PHP Web Application Development Company in USA**[https://www.dataeximit.com/php-development-services/](https://www.dataeximit.com/php-development-services/ "https://www.dataeximit.com/php-development-services/"), we at Data EximIT have...

Advantages of Hiring PHP Developer for your Website Project

PHP - Hypertext pre-processor, a scripting language used by many people in developing web pages, but most of us are unaware even of the full form. To train someone and make them learn this whole language is as difficult and time-consuming as it is...