在PHP中使用零(0)

I'm creating a calculator in PHP and wondered the best method to check a $_POST variable, I need the calculator to process all numbers including 0. And to fail if the field is empty.

This sounds easy but is_null, !empty & isset I cannot seem to get to work.

The issue is that if you use text inputs in your form they will always be set, and isset() will return true. They are set but may be empty in which case empty() would make sense, however it returns true for 0. is_null() doesn't make sense here at at all.

if(!is_numeric($_POST['something'])) {
    echo "Must be a number";
}

If you construct the inputs as an array like: <input name="numbers[first]" ...> then you can filter it easily:

$numbers = array_filter($_POST['numbers'], 'is_numeric');

if(!isset($numbers['first'])) {
    echo "Must be a number";
}

You can also check into filter_var() for more possibilities.