[FIXED] Merge flat associative array with an indexed array of associative rows to form flat associative array

Issue

I want to combine two arrays. How can I do this?

First Array:

    Array
    (
        [E1] => #43
        [B3] => Onur KAYA
        [B4] => 0555555555
        [B5] => demo@gmail.com
        [E3] => 1
        [E4] => 2017-12-24 14:31:11
        [E5] => 2018-05-26 15:17:48
        [B7] => 2018-05-16 15:33:06
        [B8] => Taslak
        [B9] => 2018-10-08 - 2019-03-11
        [B10] => 4,7363 TL 
        [B11] => 71.708 TL ($15,140 )
        [E7] => Amerika / Kaliforniya
        [E8] => Okul / Kampüs
        [E9] => Genel Akademik Sömestir - 5 ay / Sabit Tarihli
        [E10] => indirim kuponu - 33.376 TL ($7,570 )
        [E11] => 35.854 TL ($7,570 )
        [C12] => 2.368 TL ($500 )
        [F12] => 35.854 TL ($7,570 )
    )

Second Array

    Array
    (
        [0] => Array
        (
            [A15] => Kurs Ücreti (Genel Akademik Sömestir - 5 ay)
            [D15] => 22 Hafta
            [E15] => $8,200 
            [F15] => $8,200 
        )

        [1] => Array
        (
            [A16] => Konaklama Ücreti (Aile Yanı İki Kişilik - 14 öğün/hafta (AKADEMİK SÖMESTİR 5 AY - 22 HAFTAYA KADAR))
            [D16] => 22 Hafta
            [E16] => $4,695 
            [F16] => $4,695 
        )

        [2] => Array
        (
            [A17] => Transfer (Oakland Havaalanı'nden Transfer Hizmeti)
            [D17] => Tek yön
            [E17] => $145 
            [F17] => $145 
        )

        [3] => Array
        (
            [A18] => Kayıt Ücreti
            [D18] => 1
            [E18] => $185 
            [F18] => $185 
        )

        [4] => Array
        (
            [A19] => Üniversite Yerleştirme Servisi - Temel
            [D19] => 1
            [E19] => $175 
            [F19] => $175 
        )

        [5] => Array
        (
            [A20] => Seyahat ve Sağlık Sigortası
            [D20] => 22 Hafta
            [E20] => $45 
            [F20] => $990 
        )

        [6] => Array
        (
            [A21] => Birebir Ders
            [D21] => 10
            [E21] => $75 
            [F21] => $750 
        )

    )

The result I want

    Array
    (
        [E1] => #43
        [B3] => Onur KAYA
        [B4] => 0555555555
        [B5] => demo@gmail.com
        [E3] => 1
        [E4] => 2017-12-24 14:31:11
        [E5] => 2018-05-26 15:17:48
        [B7] => 2018-05-16 15:33:06
        [B8] => Taslak
        [B9] => 2018-10-08 - 2019-03-11
        [B10] => 4,7363 TL
        [B11] => 71.708 TL ($15,140 )
        [E7] => Amerika / Kaliforniya
        [E8] => Okul / Kampüs
        [E9] => Genel Akademik Sömestir - 5 ay / Sabit Tarihli
        [E10] => indirim kuponu - 33.376 TL ($7,570 )
        [E11] => 35.854 TL ($7,570 )
        [C12] => 2.368 TL ($500 )
        [F12] => 35.854 TL ($7,570 )
        [A15] => Kurs Ücreti (Genel Akademik Sömestir - 5 ay)
        [D15] => 22 Hafta
        [E15] => $8,200
        [F15] => $8,200
        [A16] => Konaklama Ücreti (Aile Yanı İki Kişilik - 14 öğün/hafta (AKADEMİK SÖMESTİR 5 AY - 22 HAFTAYA KADAR))
        [D16] => 22 Hafta
        [E16] => $4,695
        [F16] => $4,695
        [A17] => Transfer (Oakland Havaalanı'nden Transfer Hizmeti)
        [D17] => Tek yön
        [E17] => $145
        [F17] => $145
        [A18] => Kayıt Ücreti
        [D18] => 1
        [E18] => $185
        [F18] => $185
        [A19] => Üniversite Yerleştirme Servisi - Temel
        [D19] => 1
        [E19] => $175
        [F19] => $175
        [A20] => Seyahat ve Sağlık Sigortası
        [D20] => 22 Hafta
        [E20] => $45
        [F20] => $990
        [A21] => Birebir Ders
        [D21] => 10
        [E21] => $75
        [F21] => $750
    )

Solution

I solved my problem this way:

$keys = array();
$values = array();

foreach ($services_array as $service)
{
    foreach ($service as $key => $value)
    {
        array_push($keys, $key);
        array_push($values, $value);
    }
}
$combine = array_combine($keys, $values);
$merged = array_merge($excel, $combine);

Answered By – Onur KAYA

Answer Checked By – Candace Johnson (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published