Php equals语法的正确使用
有人能帮我输入以下代码吗Php equals语法的正确使用,php,comparison,Php,Comparison,有人能帮我输入以下代码吗 if ($scope = '9001') $docref = $rs["9001ref"]; elseif ($scope = '14001') $docref = $rs["14001ref"]; elseif ($scope = '18001') $docref = $rs["18001ref"]; elseif ($scope = '9001,14001') $docref = $rs["914001ref"]; elseif ($scope = '9001
if ($scope = '9001') $docref = $rs["9001ref"];
elseif ($scope = '14001') $docref = $rs["14001ref"];
elseif ($scope = '18001') $docref = $rs["18001ref"];
elseif ($scope = '9001,14001') $docref = $rs["914001ref"];
elseif ($scope = '9001,18001') $docref = $rs["918001ref"];
elseif ($scope = '14001,18001') $docref = $rs["1418001ref"];
elseif ($scope = '9001,14001,18001') $docref = $rs["91418001ref"];
我不确定是否应该使用=或==
还不确定我是否应该使用“”或“”
有人能告诉我,并提供一个简短的解释,让我知道下一步该怎么做,谢谢。在comaprison中必须有
=
if ($scope = '9001') $docref = $rs["9001ref"];
elseif ($scope == '14001') $docref = $rs["14001ref"];
elseif ($scope == '18001') $docref = $rs["18001ref"];
elseif ($scope == '9001,14001') $docref = $rs["914001ref"];
elseif ($scope == '9001,18001') $docref = $rs["918001ref"];
elseif ($scope == '14001,18001') $docref = $rs["1418001ref"];
elseif ($scope == '9001,14001,18001') $docref = $rs["91418001ref"];
对于这种情况,更好的解决方案是使用
开关
,而不是如果elseif
条件。相比之下,single=
意味着为变量赋值。例如,$scope='14001'
将14001
分配给$scope
。要进行比较,请使用=
(只要值相同)或==
(如果值和类型匹配)。使用
“
与”
基本上是代码风格的问题。但如果在字符串中使用一些变量,则“
将解析字符串以检查其中是否有变量,而”
将忽略字符串中的任何变量。例如: 您还可以在
“
包装字符串中使用以$
开头的任何变量:
echo "Variable {$variable}";
echo "String {$row['someKey']}";
echo "Object {$this->variable}";
echo "Object method that returns value {$this->getValue()}";
这里没有太多的mysql:Fm:
=
是赋值操作符,=
用于松散比较,==
用于类型和值检查
echo "Variable {$variable}";
echo "String {$row['someKey']}";
echo "Object {$this->variable}";
echo "Object method that returns value {$this->getValue()}";