0

Let's say I have an array where everything is sorted by the TemplateID value:

Array
(
    [Template 1] => Array
        (
            [0] => Array
                (
                    [CustomerID] => 1
                    [TemplateID] => Template 1
                    [ScheduledTime] => 2019-08-30 10:01:00


                )

            [1] => Array
                (
                    [CustomerID] => 2
                    [TemplateID] => Template 1
                    [ScheduledTime] => 2019-08-30 10:02:00


                )

            [2] => Array
                (
                    [CustomerID] => 3
                    [TemplateID] => Template 1
                    [ScheduledTime] => 2019-08-30 10:03:00


                )

        )

    [Template2] => Array
        (
            [3] => Array
                (
                    [CustomerID] => 4
                    [TemplateID] => Template2
                    [ScheduledTime] => 2019-07-30 10:02:00


                )

        )

)

How do I modify the array so that all unique values for ScheduledTime are their own child for each TemplateID?

I am essentially trying to create a group for everything with the same TemplateID but a different ScheduledTime like this:

Array
(
[Template 1] => Array (
[2019-08-30 10:01:00] => Array (
    [0] => Array (
        [CustomerID] => 1
        [TemplateID] => Template 1
        [ScheduledTime] => 2019-08-30 10:01:00
        )
    [1] => Array (
        [CustomerID] => 2
        [TemplateID] => Template 1
        [ScheduledTime] => 2019-08-30 10:01:00
        )
    )
[2019-08-30 10:03:00] => Array (
    [0] => Array (
        [CustomerID] => 3
        [TemplateID] => Template 1
        [ScheduledTime] => 2019-08-30 10:03:00
        )
    )
)
[Template2] => Array (
[2019-07-30 10:02:00] => Array (
    [0] => Array (
        [CustomerID] => 4
        [TemplateID] => Template2
        [ScheduledTime] => 2019-07-30 10:02:00
        )
    )
)
)
  • 2
    Maybe it would help us understand your requirement if you showed us an example of the array you want to create – RiggsFolly Jun 23 '18 at 01:28

1 Answers1

-1

truely i dont realy understand what you want but if you want make 2 array become 1 and filter unique value maybe you can use function

array_merge

you can see here for the example

huntz rahmadi
  • 116
  • 2
  • 11