This question already has an answer here:
The php code is returing true in both cases show below. I dont know why?
<?php
$cid = 150;
if ($cid=100)
{
echo $cid;
echo "<BR>";
}
if ($cid==100)
{
echo "NEW";
echo "<BR>";
echo $cid;
echo "<BR>";
}
?>
The output is:
100
NEW
100
Why is the if condition not working?
</div>
In the first if-statement you are assigning 100
to $cid
, not comparing. You're using a single =
instead of ==
. So in the first statement $cid
is set to 100
. When it comes to the second if-statement, $cid
has a value of 100
. So the conditional evaluates in a truthy value.