vendredi 23 avril 2021

If-Else loop output

<?php
$x = 1;
if ($x == 2)
    print "hi" ;
else if($x = 2)
    print $x;
else
    print "how are u";
?>

Apologies for this basic question as I am a beginner at php.

I was expecting the else statement to be executed and print "how are u", but it executed the elseif statement and printed '2' instead. May I ask why does $x become assigned to 2? Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire