I follow the example along the PHP and MySQL Web Development by Luke Welling and Laura Thomson. in chapter 6 there a //calculate button size that has each()function that deprecated in 7.2. According to the Visual studio hint. I could use foreach loop instead instead of each().
JavaScript
x
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;
}
}
Advertisement
Answer
I could use foreach loop instead instead of each().
Yes you can use foreach
instead of each()
as
JavaScript
foreach($buttons as $key => $value) {
$this->DisplayButton(
$width,
$key,
$value,
!$this->IsURLCurrentPage($value)
);
}