if (!isset($_POST['options']) || !is_array($_POST['options'])) {
// inform the user and stop execution
} else {
$options = $_POST['options'];
}
// now you can safely use count() on $options
如果数组是可选的,您可以将其初始化为空数组:
if (!isset($_POST['options'])) {
$options = [];
} elseif (!is_array($_POST['options'])
// inform the user ad stop execution
} else {
$options = $_POST['options'];
}
// now you can safely use count() on $options