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
30 Aug 2020 at 03:31 PM
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.
0
give a positive ratinggive a negative rating
31 Aug 2020 at 12:17 PM
Tim
Share on FacebookShare on TwitterShare on LinkedInSend email
x
x
Follow us on Facebook
2022 AnswerTabsTermsContact us