[英]PHP if statement not functioning correctly
I am trying to run an if statment then checks if a cell in database holds a certain value then it sets a variable, if it does not contain that value then it sets a different value 我正在尝试运行一个if语句,然后检查数据库中的某个单元格是否具有某个值,然后设置一个变量,如果不包含该值,则设置一个不同的值
I have tried the following code 我尝试了以下代码
case "Chemistry":
$type_tarin_text = ' Exp in ';
if($user_playerdata_tab['profile_type']='Drug Runner') {
$treining_value =$sp_value*11;
} else {
$treining_value =$sp_value*10;
}
$this->AddSubValueByUserID($player_id,'PlayerData','CHEMISTRY_EXP',$treining_value);
break;
It is currently setting the $treining_value as $sp_value*11 regardless of wether profile_type is 'Drug Runner' or not. 当前,无论profile_type是否为“ Drug Runner”,都将$ treining_value设置为$ sp_value * 11。
Please use ==
or strict ===
since you're expecting a string. 请使用
==
或strict ===
因为您需要一个字符串。
You're now assigning a variable which is likely not what you are trying to do. 现在,您正在分配一个变量,该变量可能与您尝试执行的操作不同。
As others have helpfully pointed out, the issue is here: 正如其他人有帮助的指出的那样,问题出在这里:
$user_playerdata_tab['profile_type']='Drug Runner'
The single =
means assignment. 单个
=
表示分配。 What you were intending to do was to test whether the two were equal. 您打算做的是测试两者是否相等。
That means using ==
- or, to be more strict, use ===
(make that your go-to equality check in the future - you'll thank us later) 这意味着使用
==
-或更严格地说,使用===
(使您将来进行均等检查-您稍后会感谢我们)
Your other assignments are fine, though I would recommend a single space both sides of your =
signs for readability 您的其他作业也可以,但我建议您在
=
符号的两侧各留一个空格,以提高可读性
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.