0

I'd like to tranform a php array in another array. More than words, let me show you the input array and the desired output array I wish. If somebody can tell me how I should realized this - no need to have full script, just ideas - I would be thankful.

input :

Array (
    [0] => Array
        (
            [0] => A
            [1] => 2023-11-14T16:30:00+0100
            [2] => 2023-11-14T18:00:00+0100
        )

    [1] => Array
        (
            [0] => A
            [1] => 2023-11-16T16:00:00+0100
            [2] => 2023-11-16T17:00:00+0100
        )

    [2] => Array
        (
            [0] => B
            [1] => 2023-11-20T09:30:00+0100
            [2] => 2023-11-20T10:00:00+0100
        )

    [3] => Array
        (
            [0] => B
            [1] => 2023-11-21T09:00:00+0100
            [2] => 2023-11-21T10:00:00+0100
        ) )

output desired:

   Array
(
    [0] => Array
        (
            [0] => 0,"A","2023-11-14T16:30:00+0100","2023-11-14T18:00:00+0100","2023-11-16T16:00:00+0100","2023-11-16T17:00:00+0100"
        )

    [1] => Array
        (
            [0] => 1,"B","2023-11-20T09:30:00+0100","2023-11-20T10:00:00+0100","2023-11-21T09:00:00+0100","2023-11-21T10:00:00+0100"
        )
)
5
  • 2
    Your output is not actually a valid array, so can you be more specific about what you want the result to be Commented Nov 13, 2023 at 15:06
  • Thanks RiggFolly, you are right. Actually I would like that for each different subarray index 0, I have the dates information in one array. So one subarray for A with all start/end dates in one array, one subarray for B with all start/end dates, for C etc... . Note here that the subarrays can have different sizes depending the number of start/end dates for each name (A,B,etc...). My difficulty is to merge the subarray accroding to the value in index 0 of the subarray. Hope my explanation is clear enough. Do not hesitate in case Commented Nov 13, 2023 at 15:38
  • Hi Markus, yes it looks like something similar I am looking. I'll dig into the thread you you showed me Commented Nov 13, 2023 at 15:41
  • I get the feeling you are making the data unusable by doing that. What is it you want to do with the result of this transformation? If you tell us that we may be able to suggest a more usable format for the array Commented Nov 13, 2023 at 15:56
  • @RiggsFolly: the final goal is to create a gantt chart with the jpgraph libraries. In other words : being able to feed the following: $activity = new GanttBar(0,"A","2001-12-21T09:30","2002-01-19T09:30", etc...); $graph->Add($activity); $activity = new GanttBar(1,"B","2001-12-21T09:30","2002-01-19T09:30", etc...); $graph->Add($activity); etc.. But with what Markus shown, I thing I'll get there. Commented Nov 13, 2023 at 16:25

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.