How can you get 1 as an output from #2?
#1
I ran this code
echo validate_email ( $email );
echo validate_password ( $password );
echo validate_username ( $username );
I get
111
which means that everything is ok.
#2
I run this code
function validate ( $email, $password, $username ) {
if ( (validate_email ( $email ) == 1)
AND (validate_password ( $password ) == 1)
AND (validate_username ( $username ) == 1 ) )
return 1;
}
echo validate ($email, $password, $username );
I get nothing as an ouput.
I tried to fix the problem by changing AND to && but the same output remains.
The output should be 1.
You get nothing as output because you are only returning
1, not actually echo-ing it. Things don’t get echo-ed to the user unless you tell PHP to do so.Example:
Also, here are a couple of points on
ifin general:&&instead ofANDas the former is more common.You don’t need the
== 1bit in there –1is alwaysTRUE. Example:Instead of: