Q:

How can i build a PHP array with a limited number of possibilities

I am trying to build a piece of code that prints the line 5 times and there are only two possible outcomes. I also want one of the outcomes to only have the possibility of appearing twice.
  <?php
    function abe( $number ) {
    $shoot = Array("alpha", "bravo");

 ?>

        <h1> Hello <?php echo $number; ?> You are on team <?php echo $shoot[array_rand($shoot)]; ?> </h1>

        <?php
            }
        ?>

        <?php abe( '1'); ?>
        <?php abe( '2'); ?>
        <?php abe( '3'); ?>
        <?php abe( '4'); ?>
        <?php abe( '5'); ?>

So ideally i want it to print five times only. I also want the "Bravo" to be printed a max amount of 2 times. How can I make it so there are only two instances of Bravo allowed?
So this may print....
Hello 1 You are on team alpha
Hello 2 You are on team alpha
Hello 3 You are on team alpha
Hello 4 You are on team alpha
Hello 5 You are on team alpha

There is a possibility that Bravo will not even print once. How can i be sure it will print 2 times?

A:

Untested, but this should be dynamic to deal with any number of players:
<?php
function abe( $number ) {
    // Input: Array Input of numbers or Names
    // Output: Team selection for each member of array Alpha||Bravo, where there can only be 2 Bravo
    $b = 0;
    $r = "";
    foreach($number as $n){
        $p = rand(0,1);
        if($p == 1){
            $b++;
        }
        if($b > 2){ $p = 0; }
        $r .= "<h1 pick='$p'>Hello $n You are on team " . (!$p?"Alpha":"Bravo") . " </h1>\r\n";
    }
    return $r;
}

echo abe(array(1,2,3,4,5));
?>

EDIT
Per your comments, here is another version that will force Bravo 2 times:
<?php
function abe( $number ) {
    // Input: Array Input of numbers or Names
    // Output: Team selection for each member of array Alpha||Bravo, where there can only be 2 Bravo
    $b = 0;
    $c = count($number);
    $r1 = rand(1,$c);
    $r2 = rand(1,$c);
    if($r1 == $r2){
        $r2++;
        if($r2 > $c){
            $r2 -= 2;
        }
    }
    $r = "";
    foreach($number as $k => $n){
        if($k == $r1 || $k == $r2){
            $r .= "<h1 pick='$k'>Hello $n You are on team Bravo</h1>\r\n";
        } else {
            $r .= "<h1 pick='$k'>Hello $n You are on team Alpha</h1>\r\n";
        }
    }
    return $r;
}

echo abe(array(1,2,3,4,5));
?>

