Pregunta

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 hay solución correcta

Otros consejos

= 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) {   
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top