How can I add string value to existing array with new index?

This is my existing array

       $array1 = Array
    (
        [id] => 1
       [name]=>XYZ]
    )

and this is my $var = ‘abc’

so I want my array1 to look like beow

        $array1 = Array
    (
        [id] => 1
        [name]=>XYZ
        [last_name] => abc
    )

how can I do this ?

You can set values to non-existant keys, and they will then exist.

1 Like