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.

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

Atleast show us the code you have sofar

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.

Member Avatar for diafol

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.