【发布时间】:2020-07-12 04:23:33
【问题描述】:
我遵循 Luke Welling 和 Laura Thomson 的 PHP 和 MySQL Web 开发示例。 在第 6 章中有一个 //calculate 按钮大小,它具有在 7.2 中弃用的 each() 函数。根据 Visual Studio 的提示。我可以使用 foreach 循环代替 each()。
public function DisplayMenu($buttons)
{
echo "<table width=\"100%\" bgcolor=\"white\"
cellpadding=\"4\" cellspacing=\"4\">\n";
echo "<tr>\n";
//calculate button size
$width = 100 / count($buttons);
while (list($name, $url) = each($buttons)) {
$this->DisplayButton(
$width,
$name,
$url,
!$this->IsURLCurrentPage($url)
);
}
echo "</tr>\n";
echo "</table>\n";
}
public function IsURLCurrentPage($url)
{
if (strpos($_SERVER['PHP_SELF'], $url) == false) {
return false;
} else {
return true;
}
}
【问题讨论】: