0

Hi

I have an array of format

Array
(
    [1] => Array
        (
            [1] => Array
                (
                    [27] => C1
                    [28] => Y1
                )

            [2] => Array
                (
                    [31] => C2
                    [32] => Y2
                )

            [3] => Array
                (
                    [34] => C3
                    [35] => Y3
                )

        )

    [2] => Array
        (
            [4] => Array
                (
                    [37] => X1
                )

            [5] => Array
                (
                    [38] => X2
                )

        )

    [3] => Array
        (
            [7] => Array
                (
                    [40] => D1
                )

            [9] => Array
                (
                    [42] => D2
                )

        )

)

with this array I need to form another array like

Array
(
    [0] => Array
        (
          [27] => C1
          [28] => Y1
          [37] => X1
          [40] => D1
        )
    [1] => Array
        (
          [27] => C1
          [28] => Y1
          [37] => X1
          [40] => D2
        )
    [2] => Array
        (
          [27] => C1
          [28] => Y1
          [37] => X2
          [40] => D1
        )
    [3] => Array
        (
          [27] => C1
          [28] => Y1
          [37] => X2
          [40] => D2
        )

    [4] => Array
        (
          [31] => C2
          [32] => Y2
          [37] => X1
          [40] => D1
        )
    [5] => Array
        (
          [31] => C2
          [32] => Y2
          [37] => X1
          [40] => D2
        )
    [6] => Array
        (
          [31] => C2
          [32] => Y2
          [37] => X2
          [40] => D1
        )
    [7] => Array
        (
          [31] => C2
          [32] => Y2
          [37] => X2
          [40] => D2
        )
    [8] => Array
        (
          [34] => C3
          [35] => Y3
          [37] => X1
          [40] => D1
        )
    [9] => Array
        (
          [34] => C3
          [35] => Y3
          [37] => X1
          [40] => D2
        )
    [10] => Array
        (
         [34] => C3
          [35] => Y3
          [37] => X2
          [40] => D1
        )
    [11] => Array
        (
          [34] => C3
          [35] => Y3
          [37] => X2
          [40] => D2
        )
)

and it should work for 'n' dimensional array not only for 3-dimensional array.

Please help me with this.....

Thanks in advance.

Edited by aithabuddy

4
Contributors
3
Replies
22
Views
4 Years
Discussion Span
Last Post by diafol
0

I don't see the transformation between the two.
What are you trying to do?

Atleast show us the code you have sofar

0

You should try implementing a triple nested loop: one that calls for the C and Y values, one for the X values and one for the D values, in that order of nesting.

Until you show us the code you tried, can we help you with some code. Do your own homework.

0

Not sure about the relationship of the original to the transformed array. It looks to me as though you're trying to build an 'all possible combinations' array from the innermost arrays.

Seems as though you may need a recursive function that retrieves the inner most items.

Interesting. Is this homework?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.