Optimized Logic to find high score
<p>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.</p>

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

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

<p>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.
    

<pre><code>$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 &lt; $size; $i++) {

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


if($checkscore1[0] &lt; $checkscore1[1]) {

    $high1++;

}else if($checkscore1[0] &gt; $checkscore1[1]) {

    $high2++;

}


}

if($high1 &gt; $high2) {

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

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

echo $winningscore;
echo $losingscore;
</code></pre>
