views:

50

answers:

1

Hi,

As far as I know when writing a conditional statement in C such as the following:

if ( some_function() == 100 && my_var == 5 ) { //do something }

is slower to execute than

if ( my_var == 5 && some_function() == 100 ) { //do something }

because it's faster to execute the my_var == 5 rather than all of the code in the function ( because if my_var != 5, then the rest of the if statement would not even be executed )...so I am wondering if the same is true for conditional statements in PHP?

+2  A: 

Yes, this is true for PHP as well, because PHP, like C, makes use of short-circuit conditional evaluation.

Michael Petrotta
Thank you very much for the quick response and the link.
dd0x