On my website i have a PHP file which generates it's menus from an external PHP file (to make updating easier)
heres part of the PHP which outlines the problem:
$products = array("Kinetic","Key","Twister","Ellipse","Focus","Trix","Classic","Pod","Halo","Alu","Rotator","Canvas","Image","Flip","Executive","Torpedo","Nature","Wafer Card","Alloy Card","Bottle Opener","Ink Pen","Clip","Light","Tie Clip","Event Lanyard","Lizzard Wristband","Slap Wristband");
$others = array("Other 1","Other 2","Other 3","Other 4","Other 5");
function genMenu($product) {
global $products;
global $others;
$menu="<div class='titlebar'><div class='title'>USBs</div></div><div class='buttons'>";
for ($x=0;$x<count($products); $x++) {
$p=$products[$x];
$link=strtolower(str_replace(' ', '', $p)).".php";
if($product==$p) {$menu=$menu."<span class='activebutton'><span class='textspace'>» ".$p."</span></span>";}
else {$menu=$menu."<a href='".$link."'><span class='button'><span class='textspace'>» ".$p."</span></span></a>";}
if(count($products)>$x+1) {
$menu=$menu."<img src='layout/seperator.jpg' class='seperator' alt='' width='184' height='2' />";
}
}
$menu=$menu."</div><div class='titlebar'><div class='title'>Other Products</div></div><div class='buttons'>";
for ($y=0;$y<count($others); $y++) {
$o=$others[$y];
$link=strtolower(str_replace(' ', '', $o)).".php";
if($product==$o) {$menu=$menu."<span class='activebutton'><span class='textspace'>» ".$o."</span></span>";}
else {$menu=$menu."<a href='".$link."'><span class='button'><span class='textspace'>» ".$o."</span></span></a>";}
if(count($others)>$y+1) {
$menu=$menu."<img src='layout/seperator.jpg' class='seperator' alt='' width='184' height='2' />";
}
}
$menu=$menu."</div>";
return (string)$menu;
}
function genDrop($product) {
global $products;
global $others;
$drop=$products[12];
return $drop;
}
So, the menu generates using an array of products i have outside the function, enabling their use by making them global... The problem im having is that when the function returns $menu
, it also changes $products
value to the same. (but not $others
)
therefore the second function (genDrop
) returns 't' from $menu="<div class='t
is this meant to happen? how do i stop it?
PHP in the HTML that calls the functions:
<?php include("menufoot.php");
$product="Twister";
$products = genMenu($product);
$dropmenu = genDrop($product);
print $dropmenu;
$footer = genFoot($product);
$mobilefooter = genMobFoot($product);
?>