The problem of isset and empty

Source: Internet
Author: User
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

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.