Why does the following code always return true?
<?php
$v = "dav6d";
if($v = "david") {
echo "smith";
}
?>
This line:
if($v = "david") {
is using an assignment (i.e. a single = sign) which will return the result of $v, "david", which is a truthy value. If you want to do a comparison use == or ===
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With