IF and ELSE without brackets not working in PHP

When I use IF and ELSE without brackets in PHP, it seem to be not working properly. Is there a difference between the functions with and without brackets ?
0
give a positive ratinggive a negative rating
Hi,

The difference is when you use IF and ELSE without brackets, it will work only with one statement after IF. For example this will work:

IF ( $a == $b ) echo "OK";
ELSE echo "NOK";

But this will not work:
IF ( $a == $b ) echo "OK"; $value = 1 ;
ELSE echo "NOK";

I recommend to use IF and ELSE with brackets, when creating conditions.
Share on FacebookShare on TwitterShare on LinkedInSend email
1 answer
x
x
2024 AnswerTabsTermsContact us