I had the same situation before.
Adding a prefix to each array value
function addPrefixToArray(array $array, string $prefix)
{
return array_map(function ($arrayValues) use ($prefix) {
return $prefix . $arrayValues;
}, $array);
}
Adding a suffix to each array value
function addSuffixToArray(array $array, string $suffix)
{
return array_map(function ($arrayValues) use ($suffix) {
return $arrayValues . $suffix;
}, $array);
}
Now the testing part:
$array = [1, 2, 3, 4, 5];
print_r(addPrefixToArray($array, 'prefix'));
Result
Array ([0] => prefix1 [1] => prefix2 [2] => prefix3 [3] => prefix4 [4] => prefix5)
print_r(addSuffixToArray($array, 'suffix'));
Result
Array ([0] => 1suffix [1] => 2suffix [2] => 3suffix [3] => 4suffix [4] => 5suffix)