Why check both isset() and !empty()

后端 未结 10 2513
难免孤独
难免孤独 2020-11-21 23:48

Is there a difference between isset and !empty. If I do this double boolean check, is it correct this way or redundant? and is there a shorter way

10条回答
  •  不知归路
    2020-11-22 00:26

    if we use same page to add/edit via submit button like below

    
    

    then we should not use

    isset($_POST['edit_id'])
    

    bcoz edit_id is set all the time whether it is add or edit page , instead we should use check below condition

    !empty($_POST['edit_id'])
    

提交回复
热议问题