Staggan Posted November 30, 2012 Share Posted November 30, 2012 Hello I have an if / or statement written as this: $winner = (!array_key_exists(0, $this->bracket[$fr]) || $s1 == -1 || $s2 == -1 ) ? '?' : (($s1 > $s2) ? $this->bracket[$fr][0]['c1'] : $this->bracket[$fr][0]['c2']); But I want to add other options as possible outcomes for winner... This is what I want to add as other options for winner, but no idea how to add it to the above statement... it should be '?' or the result in the code above, or the result from one of the lines below.. If $this->bracket[$fr][0]['c1'] = 'BY' $winner = $this->bracket[$fr][0]['c2'] or If $this->bracket[$fr][0]['c2'] = 'BY' $winner = $this->bracket[$fr][0]['c1'] Thanks Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 30, 2012 Share Posted November 30, 2012 I like the ternary operator as much as the next guy, but that code is going to be a bear to maintain. I think you would do yourself a great favor by writing out the logic if full and adding comments. I've read your question a few times and, to be honest, I don't understand what you want or, more importantly, where the logic should go. BUt, I will give it a shot. //Set the default winner value $winner = '?'; if (array_key_exists(0, $this->bracket[$fr]) && $s1 != -1 && $s2 != -1) { if ($s1>$s2 && $this->bracket[$fr][0]['c2'] = 'BY') { $winner = $this->bracket[$fr][0]['c1']; } elseif ($s1>$s2 && $this->bracket[$fr][0]['c1'] = 'BY') { $winner = $this->bracket[$fr][0]['c2']; } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.