Reputation: 91
I want to append to an existing string inside an associative array.
I know this works:
$a = ['key' => 'value'];
$a['key'] = $a['key'] . ' appended';
But am wondering of other options...
Upvotes: 0
Views: 600
Reputation: 960
I am of the opinion that you cannot do that in php.
You can't append/extend values to an existing array value in php!
All solutions are only an overwrite/replace of an existing value in an array.
Check this in php.net Arrays
Upvotes: 0
Reputation: 94662
Another option
$a = ['key' => 'value'];
$a['key'] .= ' appended';
Another option
$a['key'] = sprintf('%s %s' , $a['key'], 'appended');
Upvotes: 0