views:

101

answers:

3

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
+2  A: 

Try

$json['Request']['Header']['key'] = 'val';
RaYell
+6  A: 

Why not simply write:

$json['Request']['Header'] = array();
$json['Request']['Header']['key'] = 'val';
Paul Lammertsma
+1  A: 

Use the addition operator to append an associative array:

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