What are the advantages of using a function to create a nested array structure for an organigram in PHP?

When creating a nested array structure for an organigram in PHP, using a function can help simplify the process by allowing for easy recursion to handle nested levels of the structure. This approach makes the code more modular, reusable, and easier to maintain. Additionally, using a function can make it easier to add or remove levels or nodes in the organigram structure.

function createOrganigramNode($name, $children = []) {
    return [
        'name' => $name,
        'children' => $children
    ];
}

$organigram = createOrganigramNode('CEO', [
    createOrganigramNode('Manager', [
        createOrganigramNode('Team Lead'),
        createOrganigramNode('Team Lead')
    ]),
    createOrganigramNode('Manager', [
        createOrganigramNode('Team Lead'),
        createOrganigramNode('Team Lead')
    ])
]);

print_r($organigram);