PLS. I am very NEW to PHP so pls. understand.
OK so here it goes. . What I want to know first is that “Can a function and an if statement be in one code?” second for the code below, just take a look at where the NOTE is, what should i type in the if statement to make it say ” ARE THE SAME” if the values of the parameters $first and $second are the same and say ” ARE NOT THE SAME” if not.
<?php
function verify($first,$second)
{
echo $first . " and " . $second ;
}
echo
verify ("1","2");
if ($first === $second) /* **NOTE: I know this is wrong cause its not working** */
echo " ARE THE SAME";
else
echo " ARE NOT THE SAME";
?>
I think thats about it.
Can anyone help?
Your basic problem is one of scope. Outside
verify(),$firstand$secondare not defined. You could simply include the rest of your code inside the function body which would do what you want, eg… however functions that write to the output buffer are rarely a good idea. Instead, encapsulate the logic inside your function and leave the display to procedural code, eg