i need help to find best practice answer for current code. ill be thankful for you help.
how can i loop through this array in the best way:
$data = [
    'element1.child.property1'  => 1,
    'element1.child.property2'  => 2,
    'element2.child.name'       => 3,
    'element2.child2.name'      => 4,
    'element2.child2.position'  => 5,
    'element3.child3.position'  => 6,
];
to get answer like that
$result = [
    'element1' => [
        'child' => [
            'property1' => 1,
            'property2' => 2,
        ]
    ],
    'element2' => [
        'child' => [
            'name' => 3
        ],
        'child2' => [
            'name' => 4,
            'position' => 5
        ]
    ],
    'element3' => [
        'child3' => [
            'position' => 6
        ]
    ],
];
 
     
     
    