'Create array of mapped array keys

I am trying to create an array which shows the layout of an array.

This would be the input:

    $array = [
        'company' => [
            'contacts' => [
                'first_names',
                'last_name',
                'emails',
                'phones' => [
                    'test'
                ]
            ],
            'addresses' => [
                'postal_code'
            ],
        ]
    ];

And this is what I am trying to get the output to look like:

    $array = [
        'company.contacts.phones'
        'company.addresses'
    ];

I have been trying to work this out for hours but haven't manages to come up with a solution. It needs to work with any layout/depth of input array.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source