What are the advantages of using arrays to store variables for different layouts in PHP?

Using arrays to store variables for different layouts in PHP allows for better organization and easier maintenance of the code. It also enables the reuse of variables across multiple layouts without duplicating code. Additionally, arrays provide a convenient way to pass multiple variables to functions or templates.

// Using arrays to store variables for different layouts
$layout1 = [
    'title' => 'Homepage',
    'header' => 'Welcome to our website',
    'footer' => '© 2021 MyWebsite'
];

$layout2 = [
    'title' => 'About Us',
    'header' => 'Learn more about our company',
    'footer' => '© 2021 MyWebsite'
];

// Accessing variables for a specific layout
echo $layout1['title']; // Output: Homepage
echo $layout2['header']; // Output: Learn more about our company