用php怎么写出以下功能 $a=2 $b=3 $c='>='怎么将这三个值带入if()进行判断并输出真假用最简单的代码写一个函数
<?php
function compareValues($a, $b, $c) {
if ($c == '==') {
return $a == $b;
} elseif ($c == '!=') {
return $a != $b;
} elseif ($c == '>') {
return $a > $b;
} elseif ($c == '>=') {
return $a >= $b;
} elseif ($c == '<') {
return $a < $b;
} elseif ($c == '<=') {
return $a <= $b;
} else {
return "无效的比较运算符";
}
}
$a = 2;
$b = 3;
$c = '>=';
$result = compareValues($a, $b, $c);
if ($result === true) {
echo "真";
} elseif ($result === false) {
echo "假";
} else {
echo $result;
}
?>