Samuz Posted December 29, 2011 Share Posted December 29, 2011 Okay i'm trying to compare these sets of variables. code looks like this.. if( $row->cash > $finalcash && $row->core1 > $finalcore1 && $row->core2 > $finalcore2 && $row->core3 > $finalcore3 && $row->core4 > $finalcore4 ) { return true; } else { return false; } First question is this the appropriate way of doing this? Or would a nested if statement work better? example: if ($row->cash > $finalcash) { if ($row->core1 > $finalcore1) { if ($row->core2 > $finalcore2) { if ($row->core3 > $finalcore3) { if ($row->core4 > $finalcore4) { } else { return false; } } else { return false; } } else { return false; } } else { return false; } } else { return false; } I know it looks pretty messy, so i'm wondering if anybody is aware of an alternative to achieving this? Link to comment https://forums.phpfreaks.com/topic/253992-logical-if-statements/ Share on other sites More sharing options...
awjudd Posted December 29, 2011 Share Posted December 29, 2011 Since it returns a boolean no matter what, you don't even need the if statement. return $row->cash > $finalcash && $row->core1 > $finalcore1 && $row->core2 > $finalcore2 && $row->core3 > $finalcore3 && $row->core4 > $finalcore4; Link to comment https://forums.phpfreaks.com/topic/253992-logical-if-statements/#findComment-1302051 Share on other sites More sharing options...
Samuz Posted December 29, 2011 Author Share Posted December 29, 2011 Since it returns a boolean no matter what, you don't even need the if statement. return $row->cash > $finalcash && $row->core1 > $finalcore1 && $row->core2 > $finalcore2 && $row->core3 > $finalcore3 && $row->core4 > $finalcore4; Thanks mate. Nice & fast response. Link to comment https://forums.phpfreaks.com/topic/253992-logical-if-statements/#findComment-1302052 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.