将关联对添加到 PHP 数组
我有一个数组,我尝试写入
array_push($json['Request']['Header'], "key" => "val");
,但收到错误。编写下面的代码是可行的,但它添加了一个数组,而不仅仅是键/值
array_push($json['Request']['Header'], array("key" => "val"));
..
[0] => Array
(
[key] => val
)
//i would like
...
[key] => val
I have an array, i tried writing
array_push($json['Request']['Header'], "key" => "val");
but i received an error. Writing the below works but it adds an array instead of just the key/val
array_push($json['Request']['Header'], array("key" => "val"));
..
[0] => Array
(
[key] => val
)
//i would like
...
[key] => val
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不简单地写:
Why not simply write:
尝试
Try
使用加法运算符附加关联数组:
Use the addition operator to append an associative array: