jeudi 3 mars 2016

Can't seem to echo the right result from an array

I am currently just learning php and am doing some very basic things, which all seem to be failures lol.

I have created the code below just to test out whether I can echo the right result. So the first step was to simulate two competition entries and assign one of them as a winner. The initial IF statement is to test that there can only be one winner. This works fine.

Then I want to be able to echo "Congratulations contestant two, you are the winner". Each time I run the code, I end up with what I think is the key being output. I have tried to change it so that I try to use the key inside the echo, but that just breaks the result.

Can anyone explain what I'm doing wrong? The code is below. Thank you.

<?php

$contestant_one = false;
$contestant_two = true;

if ($contestant_one == TRUE && $contestant_two == TRUE) {

print("Only one winner!");

}
else {
    $contestant_one = "Contestant One";
    $contestant_two = "Contestant Two";

        if ($contestant_one = TRUE){    
            echo 'Congratulations '. $contestant_one .' you are the winner';
        }

        else
         {
            echo 'Congratulations '. $contestant_two .' you are the winner'; 
             }

}

?>

Aucun commentaire:

Enregistrer un commentaire