php - 如何指定 if 条件语句中返回的变量函数?
问题描述
我正在尝试根据 php 函数中返回的变量来编写我的逻辑。示例函数 xyz 有两个返回选项。所有变量 $a, $b, $c 将是动态的,返回值将根据用户在输入框中输入的内容是动态的。这些变量可以是 null 或字符串或数值。我想检查是否有任何值从 xyz 函数返回变量 $a 并根据返回的值应用逻辑。
谢谢!
function xyz($a, $b, $c){
if (!empty($a)){
return $a;
}else{
return $b;
}
}
$passingvalues = xyz(5, 2, 1);
if (!empty($passingvalues)){
echo "there is value returning";
//if returned value is $a and $a variable will have dynamic values depending on what user have entered.
if ($a){
echo "apply this logic";
}else{
echo "apply other logic";
}
} else{
echo "there is nothing returning from xyz";
}
解决方案
我最终删除了该函数并在 if 语句上添加了更多逻辑。
if (!empty($passingvalues) ){
echo "there is value returning";
//if returned value is $a and $a variable will have dynamic values depending on what user have entered.
if (!empty($a)){
echo "apply this logic";
}else{
echo "apply other logic";
}
} else{
echo "there is nothing returning from xyz";
}
推荐阅读
- python - 清理字典中的 Json 文件
- javascript - ChartJS ReactJS 对象的对象
- android - 以编程方式设置按钮和 textView 权重
- matplotlib - matplotlib 中子图的单独图例
- c++ - reinterpret_cast 没有定义的行为
- java - Bash 去除传递给 java 命令行应用程序的引号
- android-8.0-oreo - Android AMR-WB 编码问题
- java - 如何在 Java 中按下按钮来制作自定义键绑定?
- swift - SwiftUI macOS 从子视图响应菜单栏动作
- java - 如何在不自动构建的情况下使 Eclipse 中的热代码替换工作?