A calculator applet, the red Word part with empty, the result shows normal, change to isset, it is not normal. Isset and empty In this example what is the difference, why does this happen?
Receive NUM1 and num2
if (empty ($_post)) {
$r = ' Please enter a number ';
}else{
$num 1 = isset ($_post[' num1 ')? (int) $_post[' num1 ': 0;
$num 2 = isset ($_post[' num2 ')? (int) $_post[' num2 ': 0;
Receive operator
$yunsuan =isset ($_post[' Yunsuan ')? $_post[' Yunsuan ']: ' + ';
Switch ($yunsuan) {
Case ' + ':
$r = $num 1+ $num 2;
Break
Case '-':
$r = $num 1-$num 2;
Break
Case ' * ':
$r = $num 1* $num 2;
Break
Case '/':
$r = $num 1/$num 2;
Break
Default
$r = ' Please enter a number ';
Break
}
}
?>
<title>Calculator Small Program</title>
Results:
Reply to discussion (solution)
Http://www.jb51.net/article/24666.htm
if (empty ($_post)) {
And
if (!isset ($_post)) {
The effect is the same
$_post is a hyper-global variable generated by the PHP kernel, regardless of whether it is a POST submission
So Isset ($_post) is true
If you find Isset ($_post) to be false, it means that your POST submitted data is larger than the PHP default value
Obviously, this is a serious mistake.
Isset: Whether this variable exists
Empty: Whether the variable is null