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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.