将多维PHP数组转换为类似于表格的格式,并将键作为列

I have the following multidimensional array where the parent keys are long hashes, each of which contains a number of key=>value pairs which result in the following PHP data structure:

Array ( [riCQTaeQmczjR7ynRB30wzCghOhN3T82h9qXYl8M] => Array ( [Timestamp] => 2018-03-28 21:47:53 [What's your name?] => Alberto [When do you want to book] => tomorrow ) [wD5bb9lNTxmb3EftdenrO3UMJThMQ6mDhpKQFvjC] => Array ( [Timestamp] => 2018-03-28 21:48:10 [What's your name?] => AAA [When do you want to book] => next week ) [02tgD3iOH2pIyrku1m9uukwwFeISHis7C9TlMaPR] => Array ( [Timestamp] => 2018-03-28 23:30:16 [What's your name?] => Osvaldo [When do you want to book] => next week ) [aPjjcwhr2HeuFOaw3Jc0ijsf6C5VtAxOquSduIOP] => Array ( [Timestamp] => 2018-03-28 23:31:16 [What's your name?] => Jhonny [When do you want to book] => tomorrow ) )

The data structure above can be also visually represented as:

enter image description here

Notice that each one of the parent elements (i.e. long hashes) always contains the same keys as all the others (in this example each parent element contains 1 timestamp and 2 question-answer pairs).

My goal is to convert this multidimensional array into the following table-like format that can be easily exported in a csv file:

"Timestamp","What's your name?","When do you want to book?"
"2018-03-28 21:47:53","Lorna","tomorrow"
"2018-03-28 21:48:10","Jake","next week"
"2018-03-28 23:30:16","Sarah","next week"
"2018-03-28 23:31:16","Johnny","tomorrow"

The array keys become the "header", while each line represents one answer. I think one way to go would be using the PHP function array_map() but I wasn't able to achieve the desired result. Any idea / tip on how to do this?

<?php

$data = [
    [
        'Timestamp' => '2018-03-01',
        'What\'s your name?' => 'Johnny',
        'When do you want to book?' => 'tomorrow'
    ],
    [
        'Timestamp' => '2018-03-01',
        'What\'s your name?' => 'Johnny',
        'When do you want to book?' => 'tomorrow'
    ],
    [
        'Timestamp' => '2018-03-01',
        'What\'s your name?' => 'Johnny',
        'When do you want to book?' => 'tomorrow'
    ],
];

// get the headers
$headers = array_keys(array_values($data)[0]);

// open the file
$resource = fopen('output.csv', 'w');

// put the headers
fputcsv($resource, $headers);

// put the data
foreach ($data as $d) {
    fputcsv($resource, $d);
}

// close the file
fclose($resource);