How to read if a checkbox is checked in PHP?

后端 未结 18 1207
刺人心
刺人心 2020-11-22 07:54

How to read if a checkbox is checked in PHP?

18条回答
  •  [愿得一人]
    2020-11-22 08:37

    When using checkboxes as an array:

    
    
    

    You should use in_array():

    if(in_array('Orange', $_POST['food'])){
      echo 'Orange was checked!';
    }
    

    Remember to check the array is set first, such as:

    if(isset($_POST['food']) && in_array(...
    

提交回复
热议问题