I have an include on my site that provides a link to narrow a database request for each starting letter, when it is run once on the site it runs fine. However, I would like to include it both at the top and bottom of the page and this seems to cause a problem as it shows each link twice.
Below is the code in the include
<?php
$alphas = range('A', 'Z');
$url = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
foreach ($alphas as $letter) {
$elements[] = "<a href=$url?firstletter=$letter>$letter</a>";
}
echo implode(', ', $elements);
I have tried checking whether $alphas exists and only running $alphas = range('A', 'Z') if it doesn't but that didn't help.
Any ideas appreciated.
$elementsbefore theforeachi.e.$elements = array();or$elements = [];$elements = array(); foreach ($alphas as $letter) { ...