获取 $_POST 数量的最佳方法是什么
我有一个表单,用户可以在其中创建一个输入框,所以我不想允许空提交。
我试过 count($_POST)
,它总是空的。这在
if(!isset($_POST['submit'])) {
//codes
}
else {
die(count($_POST)); // return as empty
}
获取 $_POST 计数的最佳方法是什么?
最佳答案
请注意,它是您传递给 die()
(exit()
的别名)的整数!这有一个特殊的意义:
If
status
[the argument] is an integer, that value will be used as the exit status and not printed. Exit statuses should be in the range 0 to 254, the exit status 255 is reserved by PHP and shall not be used. The status 0 is used to terminate the program successfully.
(我的重点)
简单的解决方法:
if(!isset($_POST['submit'])) {
//codes
} else {
die('count=' . count($_POST)); // Now a String
}
关于php $_POST 计数问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3959196/