2017-02-14 32 views
2

阅读POST数据提交这份表格:在PHP7

<?php 
var_dump($_POST); 
var_dump(file_get_contents("php://input")); 
?> 
<form method="post" enctype="multipart/form-data"> 
<input name="test" value="0"> 
<input name="test[0].0" value="00"> 
<input name="test[0].1" value="01"> 
<input name="test[1].0" value="10"> 
<input name="test[1].1" value="11"> 
<input type="submit"> 
</form> 

结果:

array(1) { 
    ["test"]=> 
    array(2) { 
    [0]=> 
    string(2) "01" 
    [1]=> 
    string(2) "11" 
    } 
} 
string(0) "" 

我要如何在不改变的HTML代码中PHP7缺少的输入值?

+0

让他们我怀疑你能。 – ceejayoz

+6

PHP 5的行为相同。你能指望什么? 'test [0] .0'不是有效的变量名称。 –

+1

没有“multipart/form-data”,我可以从php5中的“php:// input”手动解析它,也可以从$ HTTP_RAW_POST_DATA解析。 本例中的POST数据是浏览器提交的“test = 0&test [0] .0 = 00&test [0] .1 = 01&test [1] .0 = 10&test [1] .1 = 11”。 – 2017-02-14 14:41:36

回答

3

$HTTP_RAW_POST_DATA弃用PHP 5.6PHP 7.0完全除去。

你必须改变你的html代码。

<input name="test[0][0]" value="00"> 
<input name="test[0][1]" value="01"> 
<input name="test[1][0]" value="10"> 
<input name="test[1][1]" value="11"> 

然后通过

$_POST['test'][0][0]