PHP: Avoid undefined index?

前端 未结 9 2028
闹比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条回答
  •  萌比男神i
    2021-01-17 11:46

    if(isset($products[$_POST['product']) && $products[$_POST['product'] != "")
    

    Note that a vriable can be empty but also "set" so the what comes after the && is necessary.

提交回复
热议问题