【发布时间】:2020-10-20 05:11:06
【问题描述】:
尝试了以下代码。我所能得到的只是“不工作”。
bp_is_my_profile(); //this is a Boolean.
echo bp_is_my_profile(); // this echo's out either one or nothing depending on true or false.
if ($bp_is_my_profile === "true") { // I've tried putting in numbers one and zero.
echo "Have a good morning!";
} elseif ($bp_is_my_profile === "false") { // I've tried without quotes.
echo "Have a good day!";
} else {
echo "Not working"; //whatever the Boolean is, each's it prints this line of code.
}
【问题讨论】:
-
$bp_is_my_profile未定义。您还没有在样本中的$bp_is_my_profile中存储任何东西。 -
$bp_is_my_profile = bp_is_my_profile(); -
运行函数不会自动设置变量。
-
正如@s.wadhwa 指出的那样。您需要将该行代码放在
if-else之前,还将您的true-false字符串更改为布尔值。 -
===也会检查值和数据类型。即使$bp_is_my_profile是true,$bp_is_my_profile === "true"也会返回false,因为"true"是字符串类型。
标签: php function if-statement boolean