0

希望有人可以在这里帮助我。

想象一下以下数组:

Array
(
    [blue__##__m__##__10] => 13
    [blue__##__m__##__20] => 13
    [blue__##__m__##__30] => 13
    [blue__##__xl__##__10] => 18
    [blue__##__xl__##__20] => 18
    [blue__##__xl__##__30] => 18
    [blue__##__xs__##__10] => 12
    [blue__##__xs__##__20] => 12
    [blue__##__xs__##__30] => 12
    [green__##__m__##__10] => 17
    [green__##__m__##__20] => 17
    [green__##__m__##__30] => 17
    [green__##__xl__##__10] => 15
    [green__##__xl__##__20] => 15
    [green__##__xl__##__30] => 15
    [green__##__xs__##__10] => 11
    [green__##__xs__##__20] => 11
    [green__##__xs__##__30] => 11
    [red__##__m__##__10] => 16
    [red__##__m__##__20] => 16
    [red__##__m__##__30] => 16
    [red__##__xl__##__10] => 10
    [red__##__xl__##__20] => 10
    [red__##__xl__##__30] => 10
    [red__##__xs__##__10] => 21
    [red__##__xs__##__20] => 21
    [red__##__xs__##__30] => 21
)

我想将它组织在最常见的属性上(##来自 implode*,其余的是属性)删除不太常见的属性。

结果应该是:

Array
(
    [blue] => array[13,18,12]
    [green] => array[17,15,11]
    [red] => array[16,10,21]
)

也许我必须要求用户提供排除的属性才能使其工作?例如:排除 [xs,xl,xs,10,20,30] 或按属性组 [attribute_pa_size,attribute_height] (参见原始内爆)

*内爆前的原始数组:

Array
(
    [0] => Array
        (
            [pid] => 100
            [variations] => Array
                (
                    [0] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => blue
                                    [attribute_pa_size] => m
                                    [attribute_height] => 10
                                )

                            [image_id] => 13
                        )

                    [1] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => blue
                                    [attribute_pa_size] => m
                                    [attribute_height] => 20
                                )

                            [image_id] => 13
                        )

                    [2] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => blue
                                    [attribute_pa_size] => m
                                    [attribute_height] => 30
                                )

                            [image_id] => 13
                        )

                    [3] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => blue
                                    [attribute_pa_size] => xl
                                    [attribute_height] => 10
                                )

                            [image_id] => 18
                        )

                    [4] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => blue
                                    [attribute_pa_size] => xl
                                    [attribute_height] => 20
                                )

                            [image_id] => 18
                        )

                    [5] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => blue
                                    [attribute_pa_size] => xl
                                    [attribute_height] => 30
                                )

                            [image_id] => 18
                        )

                    [6] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => blue
                                    [attribute_pa_size] => xs
                                    [attribute_height] => 10
                                )

                            [image_id] => 12
                        )

                    [7] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => blue
                                    [attribute_pa_size] => xs
                                    [attribute_height] => 20
                                )

                            [image_id] => 12
                        )

                    [8] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => blue
                                    [attribute_pa_size] => xs
                                    [attribute_height] => 30
                                )

                            [image_id] => 12
                        )

                    [9] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => green
                                    [attribute_pa_size] => m
                                    [attribute_height] => 10
                                )

                            [image_id] => 17
                        )

                    [10] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => green
                                    [attribute_pa_size] => m
                                    [attribute_height] => 20
                                )

                            [image_id] => 17
                        )

                    [11] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => green
                                    [attribute_pa_size] => m
                                    [attribute_height] => 30
                                )

                            [image_id] => 17
                        )

                    [12] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => green
                                    [attribute_pa_size] => xl
                                    [attribute_height] => 10
                                )

                            [image_id] => 15
                        )

                    [13] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => green
                                    [attribute_pa_size] => xl
                                    [attribute_height] => 20
                                )

                            [image_id] => 15
                        )

                    [14] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => green
                                    [attribute_pa_size] => xl
                                    [attribute_height] => 30
                                )

                            [image_id] => 15
                        )

                    [15] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => green
                                    [attribute_pa_size] => xs
                                    [attribute_height] => 10
                                )

                            [image_id] => 11
                        )

                    [16] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => green
                                    [attribute_pa_size] => xs
                                    [attribute_height] => 20
                                )

                            [image_id] => 11
                        )

                    [17] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => green
                                    [attribute_pa_size] => xs
                                    [attribute_height] => 30
                                )

                            [image_id] => 11
                        )

                    [18] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => red
                                    [attribute_pa_size] => m
                                    [attribute_height] => 10
                                )

                            [image_id] => 16
                        )

                    [19] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => red
                                    [attribute_pa_size] => m
                                    [attribute_height] => 20
                                )

                            [image_id] => 16
                        )

                    [20] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => red
                                    [attribute_pa_size] => m
                                    [attribute_height] => 30
                                )

                            [image_id] => 16
                        )

                    [21] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => red
                                    [attribute_pa_size] => xl
                                    [attribute_height] => 10
                                )

                            [image_id] => 10
                        )

                    [22] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => red
                                    [attribute_pa_size] => xl
                                    [attribute_height] => 20
                                )

                            [image_id] => 10
                        )

                    [23] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => red
                                    [attribute_pa_size] => xl
                                    [attribute_height] => 30
                                )

                            [image_id] => 10
                        )

                    [24] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => red
                                    [attribute_pa_size] => xs
                                    [attribute_height] => 10
                                )

                            [image_id] => 21
                        )

                    [25] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => red
                                    [attribute_pa_size] => xs
                                    [attribute_height] => 20
                                )

                            [image_id] => 21
                        )

                    [26] => Array
                        (
                            [attributes] => Array
                                (
                                    [attribute_pa_color] => red
                                    [attribute_pa_size] => xs
                                    [attribute_height] => 30
                                )

                            [image_id] => 21
                        )

                )

        )
)

谢谢

4

0 回答 0