Like the title? Question: How come some conditional statements are formatted like this? if (!empty($blah)){ echo "bleh meh"; } PHP: And some like this? if (!empty($blah)) echo "bleh meh"; PHP: Thanks, Peter
because if u have more than 1 thing to do : ex : if (!empty($blah)) { echo "bleh meh"; echo "bleh meh2"; echo "bleh meh3"; echo "bleh meh4"; echo "bleh meh5"; echo "bleh meh6"; } You should use brackets , if its only 1 call , you can put it as the second ..
Just as commandos has already said. In my personal opinion it's better practice to just use {} all the time but opinion may vary on this one...
If nothing else it makes it easier to understand what is where if (A=="1") { echo "A = 1"; } elseif (B=="1") { echo "B = 1"; } else { echo "C = 1"; }
It's probably better practice to use brackets all the time. If you do this: if ($foo == $bar) baz(); PHP: You may add a statement like this: if ($foo == $bar) baz(); bom(); PHP: without realizing that it will not do what you intended. An alternative is to use if ($foo == $bar) baz() PHP: to avoid that confusion. But whether this really matters varies from programmer to programmer.