zingzangzung
08-10-2007, 11:43 PM
I am learning php using PHP and MySQL Web Development 2nd Ed by Welling/Thomson, and tried out some from page 160 (very slightly amended). It is part of a class definition. It works ok and I understand most of it but a couple of bits of syntax confuse me. In the snippet below there are three functions. In the first I call function displayMenuItem, with three arguments. Why does the third argument have the exclamation mark before it? Does that mean NOT the return from that function? (ie switching false to true or vice versa)
Then in the actual function displayMenuItem, the arguments it accepts has $active=true, but then the function begins with if ($active). Doesn't that mean "if $active is true"?
I am getting on fine with php on the whole, but the logic of this is really confusing me. Can anyone help?
function displayMenu($links){
while(list($name, $url) = each($links))
{
$this->displayMenuItem($name, $url, !$this->IsURLCurrentPage($url));
}
}
function IsURLCurrentPage($url){
if(strpos( $GLOBALS['SCRIPT_NAME'], $url)==false){
return false;
}
else{
return true;
}
}
function displayMenuItem($name, $url, $active=true){
if ($active){
echo "<a href='$url'>$name</a><br/>";
}
else{
echo $name;
}
}
Then in the actual function displayMenuItem, the arguments it accepts has $active=true, but then the function begins with if ($active). Doesn't that mean "if $active is true"?
I am getting on fine with php on the whole, but the logic of this is really confusing me. Can anyone help?
function displayMenu($links){
while(list($name, $url) = each($links))
{
$this->displayMenuItem($name, $url, !$this->IsURLCurrentPage($url));
}
}
function IsURLCurrentPage($url){
if(strpos( $GLOBALS['SCRIPT_NAME'], $url)==false){
return false;
}
else{
return true;
}
}
function displayMenuItem($name, $url, $active=true){
if ($active){
echo "<a href='$url'>$name</a><br/>";
}
else{
echo $name;
}
}