For people who have used C/s, the menu selection function is the most basic operation, in PHP, it is also easy to implement the menu function, the method is as follows:
menu.php:
//
Author: Christine
Email:greenchn@163.net
//
Class Menu {
var $name;
var $items;
var $open;
var $closed;
var $indent;
Function menu ($name, $open = (-), $closed = (+), $indent =)
{
$this->items = Array ();
$this->name = $name;
$this->open = $open;
$this->closed = $closed;
$this->indent = $indent;
}
function Add ($name, $href = "", $target = "")
{
$n = count ($this->items);
if (Is_object ($name))
{
$this->items[$n] = $name;
}
Else
{
$this->items[$n][name] = $name;
$this->items[$n][href] = $href;
$this->items[$n][target] = $target;
}
}
Function Show ($nest = 0)
{
$urlname = STRTR ($this->name,, _);
$indent =;
Global $ $urlname;
Global $PHP _self;
Global $QUERY _string;
if ($nest)
{
$indent = Str_repeat ($this->indent, $nest);
}
if (Isset ($urlname))
{
printf (%s%s
,
$indent. $this->open,
$PHP _self,
Ereg_replace ("{$urlname}=&", $QUERY _string),
$this->name);
echo "n";
while (list (, $item) = each ($this->items))
{
if (Is_object ($item))
{
$item->show ($nest + 1);
}
Else
{
printf (%s%s
,
$indent. $this->indent,
$item [href],
(!empty ($item [target])? target= ". $item [target].":), $item [name]);
echo "n";
}
}
}
Else
{
printf (%s%s
,
$indent. $this->closed,
$PHP _self,
$urlname, $QUERY _string,
$this->name);
echo "n";
}
}
}
?>
menu2.php:
Include (menu.php);
$submenu = new Menu (Sub menu);
$submenu->add (Sub Item 1, vote.php3, _new);
$submenu->add (Sub Item 2, VOTE.PHP3);
$main = new menu (main);
$main->add (main Item 1, vote.php3?);
$main->add (main Item 2, vote.php3);
$main->add ($submenu);
$main->add (main Item 3, vote.php3);
$second = new Menu (secondary menu);
$second->add (Secondary Item 1, vote.php3);
$second->add (Secondary Item 2, vote.php3);
$main->show ();
$second->show ();
?>
You can see the menu effect by executing menu2.php.
http://www.bkjia.com/PHPjc/532235.html www.bkjia.com true http://www.bkjia.com/PHPjc/532235.html techarticle for people who have used C/s, the menu selection function is the most basic operation, in PHP, it is also easy to implement the menu function, the method is as follows: menu.php:////Author: Christine/...