<?php
$all_answers = [];
foreach($answer_files AS $file_name) {
    $answer_file = file_get_contents($file_name);
    $answers = json_decode($answer_file, TRUE);
    $one_answers = [];
    foreach($answers AS $answer_name => $answer_value) {
        $one_answers[$answer_name] = $answer_value;
    }
    $all_answers[] = $one_answers;
}

uasort($all_answers, function($a, $b) {
    if ($a['date'] == $b['date'] ) {
        return 0;
    }
    return ($a['date']  < $b['date'] ) ? -1 : 1;
});
?>
<div style="max-width: 95%; margin: 0 auto;">
    <?php
    echo '<b>Всего ответов: </b>' . count($all_answers );
    ?>
<table>
    <thead>
        <tr>
            <th>id</th>
            <th>Дата</th>
<?php
foreach($questions['questions'] AS $question) {
    echo '<th>' . $question['title'] . '</th>' . PHP_EOL;
}
?>
        </tr>
    </thead>
    <tbody>
<?php
foreach($all_answers AS $one_answers) {
    echo '<tr>';
    echo '<td>' . $one_answers['id'] . '</td>';
    echo '<td>' . date('d.m.Y H:i', $one_answers['date']). '</td>';

    foreach($questions['questions'] AS $question) {
        if(array_key_exists($question['id'], $one_answers)) {
            if(isset($question['answers'])) {
                echo '<td>' . answerval($questions, $question['id'], $one_answers[$question['id']]) . '</td>';
            } else {
                echo '<td>' . $one_answers[$question['id']] . '</td>';
            }
        }
    }
    echo '</tr>';
}
?>
    </tbody>
</table>
<?php
    foreach($counted_answer_names AS $question_id):
        echo '<b>' . questionname($questions, $question_id);
?>
    <table>
<?php
    foreach($count_answer[$question_id] AS $ca_name => $ca_value) {
        echo '<tr>';
        echo '<td>' . answerval($questions, $question_id, $ca_name) . '</td>';
        echo '<td>' . $ca_value . '</td>';
        echo '</tr>';
    }
?>
    </table>
<?php
    endforeach;
?>
</div>