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
}

没有正确的解决方案

其他提示

= 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) {   
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top