On my website, I have partners pages, each of which contains a PHP block defining array variables which are then passed to a loop that renders the content of the page. For example, for the hotels.php page, the PHP block is the following:
<?php
$hotels = [
["href" => "link1",
"src" => "src1",
"alt" => "alt1",
"name" => "name1"
],
["href" => "link2",
"src" => "src2",
"alt" => "alt2",
"name" => "name2"
],
...
];
?>
Each group of partners page has a seperate php block. Since the code of each page is pretty much the same, with only difference being the PHP blocks and the way I refer to the variables ($hotels, $restaurants, etc.) I would like to merge them into one. I would merge the PHP into one and then use the URL to find out which pages I am on and figure out which variable to use to render the page.
I could do that, the problem is that if I am visiting the hotels' page, for example, I would only be using the $hotel variable and the other ones for the different types of partners would be declared but not used.
I would like to ask if the presence of unused variables would slow down the website and if there is a way of avoiding that problem (for example making the php code lazy - variables being declared only when they are called).
staticvariables?