Is the following always acceptable code? It seems to work, but does it consistently work with all versions of PHP?
if ($x > $y)
echo 'x is greater';
elseif ($x == $y)
echo 'equal';
else
echo 'y is greater';
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That is acceptable across version and will work for as long as you want to do only one thing within each control block. Using brackets does help to make it easier to track where blocks start and end, as well as future proofing for when you need to add just one more statement.
This post has a good summary of the various options for if/else blocks in PHP.