Hailwood Posted May 12, 2010 Share Posted May 12, 2010 hey guys if i have if($a==$b) if($c==$d) return true; else return false; (nb: the lack of indentation is intentional) so my question is how does php know if the else applies to if($a==$b) or if($c==$d) Link to comment https://forums.phpfreaks.com/topic/201437-how-does-php-determine-what-if-an-else-applies-to/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 12, 2010 Share Posted May 12, 2010 The else goes with the previous if() that is at the same 'nested' statement level. For what you posted, the else is at the same statement level as the if($c==$d). To force the the else in the code you posted to go with the if($a==$b) test, you need to enclose the $c==$d logic inside of {} so that it becomes a single statement that is part of the if($a==$b) test - if($a==$b){ if($c==$d) return true;} else return false; Link to comment https://forums.phpfreaks.com/topic/201437-how-does-php-determine-what-if-an-else-applies-to/#findComment-1056866 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.