Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8696355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:15:32+00:00 2026-06-13T01:15:32+00:00

Basically this is related to a squash application where we have 2 scores. One

  • 0

Basically this is related to a squash application where we have 2 scores. One is from winner point of view and another from loser point of view.

eg.
Score1: 11-5,11-5,11-5 (Winner point of view)
Score2: 5-11, 5-11,5-11 (Loser point of view)

Now in my logic i want to find which is the winner score and which is the loser score.

I have written my logic in the below way and it does work. But i want to know if their is any other better/optimized way of writing this.

$high1 = 0;
$high2 = 0;

$score1 = "2-11,5-11,4-11,4-4";
$score2 = "11-2,11-5,11-4,4-4";

$score1Array = explode(",",$score1);

$size = sizeof($score1Array);

for($i = 0; $i < $size; $i++) {

$checkscore1 = explode("-",$score1Array[$i]);


if($checkscore1[0] < $checkscore1[1]) {

    $high1++;

}else if($checkscore1[0] > $checkscore1[1]) {

    $high2++;

}


}

if($high1 > $high2) {

$winningScore = $score2;
$losingScore = $score1;
}else{

$winningScore = $score1;
$losingScore = $score2;
}

echo $winningscore;
echo $losingscore;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:15:33+00:00Added an answer on June 13, 2026 at 1:15 am

    What about something like this:

    function is_winning($score) {
    
      $split_scores = preg_split('/(-|,)/', $score);
      $wins = $losses = 0;
    
      for($i = 0; $i < count($split_scores) / 2; $i += 2) {
        if($split_scores[$i] > $split_scores[$i + 1])
          $wins++;
        if($split_scores[$i] < $split_scores[$i + 1])
          $losses++;
      }
    
      return $wins > $losses;
    
    }
    

    Assuming $score is formatted as in your question. You can then use it like this:

    $score1 = "2-11,5-11,4-11,4-4";
    $score2 = "11-2,11-5,11-4,4-4";
    
    if(is_winning($score1)) {
      $winning_score = $score1;
      $losing_score = $score2;
    } else {
      $winning_score = $score2;
      $losing_score = $score1;
    }
    
    echo $winning_score;
    echo $losing_score;
    

    The idea is to split the score into an array where the even numbered indexes have the left score and the odd numbered indexes the right score. We then count the number of wins and the number of losses. If there’s more wins then losses then we return true since the score was a winning score. If there’s not more wins then losses we simply return false.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is related to another question I asked Basically, I have 2 horizontally
This is basically a math problem, but very programing related: if I have 1
I have (basically) this code - <script type=text/javascript language=javascript> $(document).ready(function() { $(#loadDiv).load(mypage.html, function(){ alert($(#someText).text())
The problem is basically this, in python's gobject and gtk bindings. Assume we have
I have this source code where I got it from net tutsplus. I have
I've encountered this discussion related to FK's and web applications. Basically some people say
This maybe a related question: Java assignment issues - Is this atomic? I have
There are numerous discussions here that have addressed issues that seem related to this
This is related to How to change ID in mysql I also have checked
I have a model basically like this: class Unit(models.Model): name = models.CharField(max_length=64) class UnitPrice(models.Model):

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.