Jump to content

If / Or Statement


Staggan

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/271410-if-or-statement/
Share on other sites

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'];
   }
}

Link to comment
https://forums.phpfreaks.com/topic/271410-if-or-statement/#findComment-1396481
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.