How can the indentation level of headings be defined in a PHP script when displaying a list with subpoints?

To define the indentation level of headings in a list with subpoints, you can use a recursive function that increments the indentation level for each subpoint. This function can be called recursively for each subpoint to properly display the nested structure of the list.

<?php

function displayList($items, $indentation = 0) {
    foreach ($items as $item) {
        echo str_repeat('  ', $indentation) . "- " . $item['text'] . PHP_EOL;
        
        if (!empty($item['subpoints'])) {
            displayList($item['subpoints'], $indentation + 1);
        }
    }
}

$items = [
    ['text' => 'Item 1', 'subpoints' => [
        ['text' => 'Subpoint 1'],
        ['text' => 'Subpoint 2'],
    ]],
    ['text' => 'Item 2'],
    ['text' => 'Item 3', 'subpoints' => [
        ['text' => 'Subpoint 1', 'subpoints' => [
            ['text' => 'Nested Subpoint'],
        ]],
    ]],
];

displayList($items);

?>