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
}

No correct solution

OTHER TIPS

= 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) {   
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top