我试图找出if语句在if语句完成后返回值1的原因。
$stmt = $db_con->prepare("SELECT id, username, managedby, commisionPercentage FROM `accounts` WHERE id = '$studentSignedUpBy'");
$stmt->execute();
$results = $stmt->fetchAll();
if ($results[0]['commisionPercentage'] =! 0 ) {
$agentCommisionPercentage = $results[0]['commisionPercentage'];
$commisiontype = 2;
}
echo $results[0]['managedby']; //this returns the correct value (25)
if ($results[0]['managedby'] =! 0 ) {
$managedStudentSignedUp = $results[0]['managedby'];
}
echo $results[0]['managedby']; //this returns the value 1 which ends up making $managedstudentSignedUp = 1 which is an issue.
答案 0 :(得分:2)
您的代码:
if ($results[0]['managedby'] =! 0 ) {
分解这是分配相反的值0(falsy),这是布尔值true。当你echo
时,类型被变成juggled并输出为1的整数。
显然,您希望使用!=
进行比较而不是分配。
答案 1 :(得分:0)
if条件运算符的问题
不是
=!
它将是!=
查看详细信息