Q:

Lower child array keys and combine items

I've one array
$arr = [
    'parent' => [
        'CHILD' => [
            5,6
        ],
        'child' => [
            1,2,3,4
        ],
        'Child' => [
            5,6,7,8
        ],
        ...
    ]
];

I want to lower the child keys and combine each child having the same case insensitive keys like
$arr = [
    'parent' => [
        'child' => [
            1,2,3,4,5,6,7,8
        ],
    ]
];

I've tried with array_change_key_case which always takes the last element and ignores the others.
An array may have multiple children with the same key (with different case)

A:

Try the code below should work:
<?php
$arr = [
    'parent' => [
        'CHILD' => [
            5,6
        ],
        'child' => [
            1,2,3,4
        ],
    ]
];
$arNew = [];
foreach ($arr as $sParent => $ar) {
    foreach ($ar as $sChild => $ar1) {
        $sChild = strtolower($sChild);
        if (empty($arNew[$sParent][$sChild])) {
            $arNew[$sParent][$sChild] = $ar1;
        } else {
            $arNew[$sParent][$sChild] = array_merge($arNew[$sParent][$sChild], $ar1);
        }
    }
}

print_r($arNew);

