I was messing around with some PHP codes and found this which baffles me
DisplayButton($width, $name, $url, $judge);
public function DisplayButton($width, $name, $url, $active = true)
{
if ($active)
{
echo "<td width ='$width%'>
<a href ='$url'>
<img src ='s-logo.gif' alt ='$name' border ='0' /></a>
<a href ='$url'><span class='menu'>$name</span></a></td>";
}
else
{
echo "<td width ='$width%'>
<img src ='side-logo.gif'>
<span class='menu'>$name</span></td>";
}
}
how could you define a parameter like $active=true in this case, because as I believe that the value of the passed boolean variable $judge(either true or false) is going to be forced to change to true because of the $active= true, so how could it possibly reach to the else statement? I probably misunderstood the argument $active=true, but how? Thank you very much
Pass
false, nottrueto reach thatelseblock$active = trueat function declaration means that parameter is optional, so you can omit it while call the function. But if you pass it, then default value doesn’t affect in any way.