3

我有一个数组,我试着写

array_push($json['Request']['Header'], "key" => "val");

但我收到一个错误。编写以下内容,但它添加了一个数组,而不仅仅是 key/val

array_push($json['Request']['Header'], array("key" => "val"));

..
[0] => Array
        (
            [key] => val
        )

//i would like
...
[key] => val
4

3 回答 3

6

为什么不简单地写:

$json['Request']['Header'] = array();
$json['Request']['Header']['key'] = 'val';
于 2009-10-06T14:39:55.467 回答
2

尝试

$json['Request']['Header']['key'] = 'val';
于 2009-10-06T14:39:42.423 回答
1

使用加法运算符附加关联数组:

$json['Request']['Header'] += array("key" => "val");
于 2009-10-06T14:40:23.007 回答