What is the preferred way to write this if statement, and why?
What is the preferred way to write this if statement, and why?
if( 5 == $someVar ) or if( $someVar == 5 )
Writing is my profession! I have written hundreds of article for many organizations and looking forward to work with growing organization. I am compatible to produce content in many categories including International politics, Healthcare, Education, Lifestyle, etc.. I understand the value of your time that you have invested to read my bio. #thanks
KIRTI SHARMA
03-Nov-2022The if( $someVar == 5 ) is the preferred way to assign condition under the if situation.
Siddhi Malviya
28-Oct-2022The former, as it prevents accidental assignment of 5 to $someVar when you forget to use 2 equalsigns($someVar = 5), and will cause an error, the latter won't.