Trying to use the implode()
function to add a string at the end of each element.
$array = array('9898549130', '9898549131', '9898549132');
$attUsers = implode("@txt.att.net,", $array);
print($attUsers);
Prints this:
[email protected],[email protected],9898549132
How do I get implode()
to also append the glue for the last element?
Expected output:
[email protected],[email protected],[email protected]
//^^^^^^^^^^^^ See here
There is a simpler, better, more efficient way to achieve this using array_map
and a lambda function:
$numbers = ['9898549130', '9898549131', '9898549132'];
$attUsers = implode(
',',
array_map(
function($number) {
return($number . '@txt.att.net');
},
$numbers
)
);
print_r($attUsers);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With