有没有人能帮我写一下下面的代码
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"];我不确定我应该使用=还是==
我也不确定我应该用‘’还是“”
谁能让我知道,并提供一个简短的解释,以便我知道下一步,谢谢。
发布于 2014-10-07 16:01:28
相比之下,单个=意味着您正在为变量赋值。例如,$scope = '14001'会将14001赋值给$scope。要比较某些内容,请使用== (如果值相同)或=== (如果值和类型匹配)。
与"相比,使用'基本上是代码风格问题。但是如果你在字符串中使用一些变量,那么"将解析字符串以检查其中是否有任何变量,而'将忽略字符串中的任何变量。
例如:
$scope = '123';
echo "My scope is {$scope}"; // will echo "My scope is 123";
echo 'My scope is {$scope}'; // will echo "My scope is {$scope}";您还可以在"包装字符串中使用任何以$开头的变量:
echo "Variable {$variable}";
echo "String {$row['someKey']}";
echo "Object {$this->variable}";
echo "Object method that returns value {$this->getValue()}";发布于 2014-10-07 15:54:25
在监狱里一定要有==
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"];对于这种情况,更好的解决方案是使用switch而不是if-elseif条件。
https://stackoverflow.com/questions/26231103
复制相似问题