Php 在html表单数组中使用空键

Php 在html表单数组中使用空键,php,html,forms,post,Php,Html,Forms,Post,在html表单中,可以将数据作为数组发送 <!-- This is an associative array --> <input name="table[key1]"> <input name="table[key2]"> <!-- This is an index-based array --> <input name="table[]"> <input name="table[]"> 是否可以使用空字符串作为键

在html表单中,可以将数据作为数组发送

<!-- This is an associative array -->
<input name="table[key1]">
<input name="table[key2]">

<!-- This is an index-based array -->
<input name="table[]">
<input name="table[]">

是否可以使用空字符串作为键将值存储到关联数组中?

因此,php可以使用
$\u POST[“table”][null]

null
访问数据不是空字符串,而是
'
'
。 但是,PHP会将其转换为空字符串并将其用作键(请参见示例1中的)

所以这些是等价的:

$a = array('' => 'hello');
$b = array(null => 'hello');

从您的示例中,数据将位于
$\u POST[“table”][“”]

我知道当用作数组键时,null将强制转换为空字符串,我只是将其用作语法糖。现在的问题是如何从代码的html端将空字符串键插入数组?我看到@Estecka,我误解了这个问题。您是否尝试过
,或者您只是在寻找使用
null
的方法?我尝试过,
表['''']
生成字符串
'''
,而不是空字符串。