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
0give a positive ratinggive a negative ratingshow more
StorStor
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.
31 Aug 2020 at 12:17 PM
0give a positive ratinggive a negative ratingshow more
TimTim
Share on FacebookShare on TwitterShare on LinkedInSend email
Follow us on Facebook
2022 AnswerTabsTermsContact us