Since I started learning php recently, I always use { after IF. For example:
if ($_SERVER['REQUEST_METHOD'] == "POST") {
echo "okay";
}
I was watching a tutorial the other day and noticed that the person did not use those braces e.g.:
if ($_SERVER['REQUEST_METHOD'] == "POST")
echo "okay";
I tried this myself and the code still worked. I am confused now as to whether I need the braces or not if I don't have an else to add afterwards. I would rather use the braces always so I don't forget about them but just wondered if it is okay to do so even if there isn't an ELSE accompanying the IF.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.