问题是我正在处理多维数组。让我用一个简单的例子向您解释这个问题: 考虑一个像这样的表:
<form method="post" id="f">
<table class="table table-bordered" id="example">
<tbody>
<?php for ($a = 0; $a <= 101; $a++) { ?>
<tr>
<?php for ($b = 0; $b <= 20; $b++) { ?>
<td><input type="text" name="columnVal<?php echo $b; ?>[]" value="<?php echo $a . '-' . $b; ?>" /></td>
<?php } ?>
</tr>
<?php } ?>
</tbody>
<input type="submit" class="btn btn-primary" value="upload" name="upload" />
</table>
</form>
上面的表格有一张表,其中tr和td是动态的,在某种意义上说,我使用php代码来循环输入文本,并且其中的值现在类似于rownumber dash columnnumber。我希望在提交时看到一个完整的列文本框值。所以在服务器脚本中,我需要 PHP代码是
if(isset($_POST['upload'])){
print_r($_POST['columnVal0']);
exit();
}
所以输出应该是所有第一列值为0-0,1-0,2-0 .... 101-0的数组? 但问题是我得到一半的价值。例如0-0,0-1,0-2(最多45-0)。 尽管我使用了ini_set('max_input_vars','9999');某些我如何感觉到它的max_input_var问题,但是我不确定,如果您认为它确实存在这个问题,请告诉我如何解决。但它不起作用。如果您知道如何分配ram大小的数组或如何知道数组的大小(以MB为单位),也请告诉我。 我知道这有点复杂,但是我希望有人能解决我的问题并帮助我解决!对不起,英语不好!
答案 0 :(得分:0)
您的代码工作正常,为了便于阅读,我对其进行了一些改进:
HTML表单:
<form action="test.php" method="post" id="f">
<table class="table table-bordered" id="example">
<?php
for ($a = 0; $a < 101; $a++) {
echo '<tr>';
for ($b = 0; $b <= 20; $b++) {
echo '<td>
<input type="text" name="columnVal'.$b.'[]" value="'.$a.'-'.$b.'" />
</td>';
}
echo '</tr>';
}
?>
<input type="submit" class="btn btn-primary" value="upload" name="upload" />
</table>
</form>
表单操作:
<?php
if(isset($_POST['upload'])){
print_r($_POST['columnVal0']);
exit();
}
?>
第一次尝试,我得到了与您相同的错误消息,即max_input_var,它是php.ini中的注释指令,设置为1000。请取消注释它并将其设置为所需的值。 这样,您将获得所需的完整列列表:
Array ( [0] => 0-0 [1] => 1-0 [2] => 2-0 [3] => 3-0 [4] => 4-0 [5] => 5-0 [6] => 6-0 [7] => 7-0 [8] => 8-0 [9] => 9-0 [10] => 10-0 [11] => 11-0 [12] => 12-0 [13] => 13-0 [14] => 14-0 [15] => 15-0 [16] => 16-0 [17] => 17-0 [18] => 18-0 [19] => 19-0 [20] => 20-0 [21] => 21-0 [22] => 22-0 [23] => 23-0 [24] => 24-0 [25] => 25-0 [26] => 26-0 [27] => 27-0 [28] => 28-0 [29] => 29-0 [30] => 30-0 [31] => 31-0 [32] => 32-0 [33] => 33-0 [34] => 34-0 [35] => 35-0 [36] => 36-0 [37] => 37-0 [38] => 38-0 [39] => 39-0 [40] => 40-0 [41] => 41-0 [42] => 42-0 [43] => 43-0 [44] => 44-0 [45] => 45-0 [46] => 46-0 [47] => 47-0 [48] => 48-0 [49] => 49-0 [50] => 50-0 [51] => 51-0 [52] => 52-0 [53] => 53-0 [54] => 54-0 [55] => 55-0 [56] => 56-0 [57] => 57-0 [58] => 58-0 [59] => 59-0 [60] => 60-0 [61] => 61-0 [62] => 62-0 [63] => 63-0 [64] => 64-0 [65] => 65-0 [66] => 66-0 [67] => 67-0 [68] => 68-0 [69] => 69-0 [70] => 70-0 [71] => 71-0 [72] => 72-0 [73] => 73-0 [74] => 74-0 [75] => 75-0 [76] => 76-0 [77] => 77-0 [78] => 78-0 [79] => 79-0 [80] => 80-0 [81] => 81-0 [82] => 82-0 [83] => 83-0 [84] => 84-0 [85] => 85-0 [86] => 86-0 [87] => 87-0 [88] => 88-0 [89] => 89-0 [90] => 90-0 [91] => 91-0 [92] => 92-0 [93] => 93-0 [94] => 94-0 [95] => 95-0 [96] => 96-0 [97] => 97-0 [98] => 98-0 [99] => 99-0 [100] => 100-0 )
对于以MB为单位的数组大小,此处报告了我能找到的最佳答案:php get array's data size和https://nikic.github.io/2011/12/12/How-big-are-PHP-arrays-really-Hint-BIG.html