What are the security implications of using an array to include files in PHP scripts?

Using an array to include files in PHP scripts can pose a security risk if the array is not properly sanitized. If user input is used to populate the array, it could potentially allow for directory traversal attacks or include arbitrary files. To mitigate this risk, it is important to validate and sanitize any user input before using it to populate the array.

// Sanitize user input before populating the array
$allowed_files = ['file1.php', 'file2.php', 'file3.php'];

if (in_array($_GET['file'], $allowed_files)) {
    include $_GET['file'];
} else {
    echo "Invalid file requested";
}