【发布时间】:2016-03-21 18:37:17
【问题描述】:
如果可以的话,非常感谢您阅读和回复。
- 在一个函数中,我测试一个条件并创建一个字符串“真”或“假”,然后我创建一个全局变量。
- 然后我以该字符串为参数调用另一个函数
-
在该函数的 if 语句中,我想根据字符串布尔值 'true' 或 'false' 进行测试
$email_form_comments = $_POST['comments']; // pull post data from form if ($email_form_comments) $comments_status = true; // test if $email_form_comments is instantiated. If so, $comments_status is set to true else $error = true; // if not, error set to true. test_another_condition($comments_status); // pass $comments_status value as parameter function test_another_condition($condition) { if($condition != 'true') { // I expect $condition to == 'true'parameter $output = "Your Condition Failed"; return $output; } }
我的想法是 $condition 将保持一个“真”值,但事实并非如此。
【问题讨论】:
-
$string 里面真的有值吗?否则 $status 显然会是错误的。另外,我不会使用“true”字符串,我只会使用实际的布尔值。
-
您可能打算使用另一条评论中概述的
if($condition != true),检查 PHP 的 TRUE 常量,而不是字符串文字和$status = true;,所以很难在这里说出您想要做什么. php.net/manual/en/language.types.boolean.php -
我已经留下了这个问题。
标签: php boolean parameter-passing