Reputation: 111
I am new in php and trying to compare two variable in it. I have tried like below but its always returning true even its not matching.
<?php
$messages ="test";
if ($messages = "Support" || "support") {
echo "matching";
}
else{
echo "not matching"; }
?>
Let me know if someone can help me for solve it. Thanks
Upvotes: 0
Views: 49
Reputation: 82
You are using = which is used for assignment, yo can use == or === (strict comparison) to compare strings.
Upvotes: 1
Reputation: 1884
You're doing a assignation.
On PHP, = sign are assignation one. For comparision, you need to use ==.
On your current operation, you're doing a comparision, and then, an assignation. "a" || "A" is equal to 1 (true). Then, you're assigning true to your variable $messages.
Change the line to:
if ($messages == "Support" || $messages == "support")
Upvotes: 1