Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用迭代器计算帖子数_Php_Post_Count - Fatal编程技术网

Php 使用迭代器计算帖子数

Php 使用迭代器计算帖子数,php,post,count,Php,Post,Count,我能数一数有多少帖子被提交为字段\金额\ 1、字段\金额\ 2、字段\金额\ 3等。。。像这样 $Counting = count($_POST['Field_Amount_']); 感谢您的建议,最简单的方法是修改您的表格,如: <input name="Field_Amount[]" type="text" /> <input name="Field_Amount[]" type="text" /> <input name="Field_Amount[]" t

我能数一数有多少帖子被提交为字段\金额\ 1、字段\金额\ 2、字段\金额\ 3等。。。像这样

$Counting = count($_POST['Field_Amount_']);

感谢您的建议,最简单的方法是修改您的表格,如:

<input name="Field_Amount[]" type="text" />
<input name="Field_Amount[]" type="text" />
<input name="Field_Amount[]" type="text" />
然后你可以只做
count($\u POST['Field\u Amount'])

另一种方法是手动计算所有元素:

$keys = array_keys($_POST);
$counted = count(preg_grep('/^Field_Amount_\d+$/', $keys));
如果您还需要确保只跟踪非空字段,则可以将空字符串作为第二个参数提供给
array\u keys

$keys = array_keys($_POST, '');
$counted = count(preg_grep('/^Field_Amount_\d+$/', $keys));

如果你需要做更多的验证,那么你需要手动循环。

你可以只做计数($\u POST)。这是关键!非常感谢。
if($_POST['Submit']) {

    $count=0;

    foreach( $_POST as $post ) {
        if( strstr($post, "field_amount_")) {
            $count++;
        }
    }
    echo $count;
}
if($_POST['Submit']) {

    $count=0;

    foreach( $_POST as $post ) {
        if( strstr($post, "field_amount_")) {
            $count++;
        }
    }
    echo $count;
}