php - 在html表单数组中使用空键
问题描述
在 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就可以访问数据了$_POST["table"][null]
解决方案
null
不是空字符串,应该是 a''
或 a ""
。但是,PHP 会将其转换为空字符串并将其用作键(在示例 1 下查看https://www.php.net/manual/en/language.types.array.php)
所以这些是等价的:
$a = array('' => 'hello');
$b = array(null => 'hello');
从您的示例中,数据将在$_POST["table"][""]
推荐阅读
- ruby-on-rails - 如何为模型设置随机数 before_save?
- node.js - Mongoose:更新数组中的对象(批量写入)
- regex - 正则表达式(记事本++)插入,而不是替换
- asp.net - 登录 Blazor 服务器应用程序时如何显示加载图标?
- php - PHP 没有得到改造发送的 JSON 值
- go - 使用 goavro 处理多种类型的解码数据
- javafx - 在 Javafx 中设置 DatePicker 箭头按钮的样式
- ruby-on-rails - 从文件夹中获取照片时,Rails、活动存储、attach_one 照片不起作用
- reactivesearch - ReactiveSearch 自定义组件和清除过滤器
- flutter - 在 Flutter/Dart AVD 中颜色“锁定”为相似颜色