php $_POST 计数问题

标签 php

获取 $_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/

相关文章:

php - 在 PHP 中将 & 转换为 & for XML

php - 如何将数据插入2个不同的表(php mysql)

php - Discord PHP 从 channel ID 创建邀请链接

php - 子文件夹 codeigniter 3 中的默认 Controller 无法正常工作

php - 使用 .htaccess 重写 URL 使重复的 mysql 条目

php - Preg 仅替换数字和/或用百分比表示的数字

php - 有一些酒吧不是 highcharts 上的 url 链接

PHPUnit:测试完成后如何从数据库中删除测试数据?

php - 我可以根据变量的值和名称找出变量是否在全局空间中定义吗?

php - 如何在数据库中插入由 preg_match_all 获得的数组