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...
CodePudding user response:
Another option
$a = ['key' => 'value'];
$a['key'] .= ' appended';
Another option
$a['key'] = sprintf('%s %s' , $a['key'], 'appended');
CodePudding user response:
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