"P1 attacks P2" and "P2 attacks P1" This is just my simple structure. I want to know if there is a better way than this because I have so many lines of code already.

    &lt;?php
$p1speed = 5;
$p2speed = 3;

//way for next turn: 1 for turn
$p1 = 0;
$p2 = 0;

if($p1speed&gt;$p2speed) {

    $p1 = 1;
    $p2 = 0;

}
else if($p2speed&gt;$p1speed) {

    $p1 = 0;
    $p2 = 1;

}

$count=0;

//begin
while($count&lt;5){

    if($p1==1) {

        echo 'P1 turns &lt;br&gt;';

        //adjust
        $p1 = 0;
        $p2 = 1;

    }
    else if($p2==1) {

        echo 'P2 turns &lt;br&gt;';

        //adjust
        $p1 = 1;
        $p2 = 0;

    }

    $count++;

}
?&gt;
This is a refactoring of the original code. It picks the starting player and then uses a simple toggle ($currentPlayer = ($currentPlayer == 1) ? 2 : 1;) to determine which player goes next for 5 rounds. 

$currentPlayer = 1;

if ($player2speed &gt; $player1speed) {

    $currentPlayer = 2;

}

$count = 0;

while ($count &lt; 5) {

    echo $currentPlayer . " turns&lt;br/&gt;";

    $currentPlayer = ($currentPlayer == 1) ? 2 : 1;

    $count ++;
}


Note, the current code fails if both player's speeds are the same.