php dizi birleştirmek

0 Cevap php

Ben sonraki dizi var:

Array
(
    [0] => Array
        (
            [id] => 160
            [payment_period] => Monthly
            [plan_payment_type_id] => 171
            [payment_type_id] => 4
        )
    [1] => Array
        (
            [id] => 160
            [payment_period] => Monthly
            [plan_payment_type_id] => 172
            [payment_type_id] => 5
        )
    [2] => Array
        (
            [id] => 161
            [payment_period] => Weekly
            [plan_payment_type_id] => 173
            [payment_type_id] => 9
        )
)

I need to group this array by id. How can I do it in the best way? My output should be:

Array
(
    [0] => Array
        (
            [id] => 160
            [payment_period] => Monthly
            [payment_types] => Array(
                [0] => Array(
                    [plan_payment_type_id] => 171
                    [payment_type_id] => 4
                )
                [1] => Array(
                    [plan_payment_type_id] => 172
                    [payment_type_id] => 5
                )
            )
        )
    [1] => Array
        (
            [id] => 161
            [payment_period] => Weekly
            [payment_types] => Array(
                [0] => Array(
                    [plan_payment_type_id] => 173
                    [payment_type_id] => 9
                )
            )
        )
)

Çok teşekkür ederim.

0 Cevap