I am writing a simple php code to check if number is odd or even -
i trying write simple php code see if number odd or keep getting error saying "expected statment" after closing bracket on if statement. can please explain need do?
<?php function odd_or_even($num) { if ($num % 2 == 0); { print'number even'; } else { print 'odd'; } }
posting community wiki.
as stated in comments:
if ($num % 2 == 0); ^ ends/terminates statement.
as per manual states on line termination:
as in c or perl, php requires instructions terminated semicolon @ end of each statement. closing tag of block of php code automatically implies semicolon; not need have semicolon terminating last line of php block. closing tag block include trailing newline if 1 present.
reference:
answer: remove it.
taken comments:
"the else
unexpected because conditional becomes 1 liner nothing. expected statment op mentions mis-quoted error message. – chris85"
what posted should have thrown following error:
parse error: syntax error, unexpected 'else' (t_else)
but failed post actual error message.
Comments
Post a Comment