comparing two variables returns false result

后端 未结 5 1077
感情败类
感情败类 2021-01-25 13:27

Why does this always return true:

$s = \'334rr\';
$i = (int)$s;

if ($i == $s) {
    echo true;
} else {
    echo false;
}

If I ec

5条回答
  •  猫巷女王i
    2021-01-25 14:01

    PHP converts the $s string to an integer when comparing to another integer ($i). It basically does this (well, i don't know what it does internally, but it boils down to this):

    if($i == (int) $s)
    

    Which makes the statement true

提交回复
热议问题