PHP: Avoid undefined index?

前端 未结 9 1909
闹比i
闹比i 2021-01-17 11:18

Every time a POST value is not equal to the list of values set in an array will return: Undefined Index error, I made an if statement but is not working.

Here\'s the

9条回答
  •  太阳男子
    2021-01-17 11:33

    @$_POST['product']
    

    (with an @) will return the same thing as :

    $product = (isset($_POST['product'])) ? $_POST['product'] : null;
    

    Shorter is sweeter !! 4 times less code ! Easier to read and understand.

    The @ symbol is the error control operator (AKA the "silence" or "shut-up" operator). It makes PHP suppress any error messages (notice, warning, fatal, etc.).

    But beware not to use @ for any other thing, as it would make your code so much harder to debug!

    (this will answer your question before the edit)

提交回复
热议问题