Question

Why does the variable change within this if statment

$userid = 500;
echo "User ID" . $userid; // Outputs 500

if($userid=362) {   
  echo "User ID" . $userid . "x"; // Outputs 362
}

Pas de solution correcte

Autres conseils

= is the assignment operator. So your if statement is assigning the value of 362 to $userid. What you want to use is == which is a comparison operator:

if($userid=362) {   

should be

if($userid==362) {   
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top