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 ?
30 Aug 2020 at 03:31 PM
0pnshow more

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.
31 Aug 2020 at 12:17 PM
0pnshow more
Share on FacebookShare on TwitterShare on LinkedInSend email
Follow us on Facebook & Twitter
2022 AnswerTabsTermsContact us