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));


php arrays

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Hire Dedicated PHP Developer

Looking to hire affordable yet experienced PHP developers? **[Hire Dedicated PHP Developer](https://hourlydeveloper.io/hire-dedicated-php-developer/ "Hire Dedicated PHP Developer")**, who can convert your idea to reality, within the stipulated...

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...

How to use highchart in php with example

Here, i will let you know that how to use highchart in php application with example. Highchart provides feature to draw different type of charts.

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...

PHP Website Development

Skenix Infotech is a leading PHP Web Development Company that helps companies get results with industry best practices. Get affordable PHP Development Services.